In R i run a ncvTest for heteroscedasticity. But i can't seem to print the result into a csv file. This is what i have done,
ncvt<-ncvTest(pol_reg)
outss<-file(paste0("hetero_test.csv"))
write.csv(ncvt,outss)
I get the following error message,
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ""chisqTest"" to a data.frame
What am I suppose to do in order to save the result into a csv file. The result of ncvt looks as follows,
Non-constant Variance Score Test
Variance formula: ~ fitted.values
Chisquare = 75514.06 Df = 1 p = 0
You can pull out components of your ncvt list and make a dataframe out of it to write to a csv file:
ncvt<-ncvTest(pol_reg)
ds_ncvt <- data.frame(ncvt$formula.name, ncvt$ChiSquare, ncvt$Df, ncvt$p, ncvt$test)
outss<-file(paste0("hetero_test.csv"))
write.csv(ds_ncvt,outss)
Thanks, the following also works
ncvt<-ncvTest(pol_reg)
ds_ncvt <- as.matrix(ncvt)
outss<-file(paste0("hetero_test.csv"))
write.csv(ds_ncvt,outss)
Related
I have created my own data set named as Kwality.csv in Excel and when I am executing above code I am not able to get histogram for the same data and it's throwing me error like this:
Error in hist.default(mydata) : 'x' must be numeric
library(data.table)
mydata = fread("Kwality.csv", header = FALSE)
View(mydata)
hist(mydata)
I tried to reproduce you work flow and exported xlsx-file into csv-file (using export to comma-separated file).
First, you should check what kind of character is used for variable and decimal places separation. In my case, for variable separation it is the ; semicolon, and the decimal places is "," comma.
Then you should choose the column, which you will use for the histogramm plot with the function[[]]. The data table itself is not a valid argument for hist function. Please see as below.
See below:
Taken this into consideration you cod execute your code:
library(data.table)
# load csv generatd by NORMSINV(RAND()) in Excel
mydata = fread("check.csv",header = FALSE, sep = ";", dec = ",")
mydata
#hist(mydata)
# Error in hist.default(mydata) : 'x' should be numeric
# does not work
# access by column, e.g. third colum - OK
hist(mydata[[3]])
Output:
I am using ChemoSpec to analyse FTIR spectra in R.
I was able to import several csv files using files2SpectraObject, applied some of the data pre-processing procedures, such as normalization and binning, and generated new SpectraObjects with the results.
Is it possible to export data back to csv format from the generated SpectraObjects?
So far I tried this
write.table(ftirbin, "E:/ftirbin.txt", sep="\t")
and got this:
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ""Spectra"" to a data.frame
Thanks in advance!
G
If you look at ?Spectra you'll see how a Spectra object is stored. The intensity values are in your_object$data, and the frequency values are in your_object$freq. So you can't export the whole object (it's not a data frame, but rather a list), but you can export the pieces. To export the frequencies in the first column, and the samples in the following columns, you can do this (example uses a built in data set, SrE.IR):
tmp <- cbind(SrE.IR$freq, t(SrE.IR$data))
colnames(tmp) <- c("freq", SrE.IR$names)
tmp <- as.data.frame(tmp) # it was a matrix
Then you can write it out using write.csv or write.table (check the arguments to avoid row numbers).
I am new to R and want to perform a linear regression from the data in a CSV file as follows:
Data = read.csv("ErrorTest.csv",header=T, row.names=NULL)
regmodel=lm(Error ~ Const, data = Data)
However, I am getting the error message:
"Error in eval(expr, envir, enclos) : object 'Error' not found"
The CSV file is uploaded here: http://www.filedropper.com/errortest
Can someone please explain how to do the regression in R correctly?
The first few lines of your csv file look like this:
Error;Const
-0,44;1
-0,58;1
1,10;1
The read.csvassumes the use of , as separator between data and . as decimal point character. Meanwhile, judging from your data above, this is not the case. Therefore, you must modify the code used to read in the csv file. After that, you can run the regression model.
Data <- read.csv("ErrorTest.csv", sep = ";", dec = ",")
regmodel <- lm(Error ~ Const, data = Data)
EDIT: An even simpler way of reading in the data is using the built-in function read.csv2:
read.csv2("Errortest.csv")
I have been using the R package "Player Rating" and I have worked the examples, however when I try to export the output (the rating tables) to a CSV I get the following message:
write.csv(sobj, file = "output.csv")
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ""rating"" to a data.frame
https://cran.r-project.org/web/packages/PlayerRatings/PlayerRatings.pdf
You can only export data.frame/matrix etc using write.csv . The object robj(in your code 'sobj') that you are trying to export is a list. Inside it , it has data.frame "ratings" do as said by #user20650
write.csv(robj$ratings, file = "output.csv")
I have a .sav file. I want to print out the data properly as PSPP variable view in R.
Succeeded to print the type of data, but not the other specific sg.: width, label, value label,...
I using following command to read data:
library(foreign)
library(memisc)
data <- read.spss("Database.sav", use.value.labels = FALSE,
max.value.labels = 100)
x = do.call(rbind,data)
Please check the following command for variable and value labels read from SPSS in R. Hope this will work...
library(foreign)
## Read SPSS data
data<-read.spss("Database.sav",use.value.labels=FALSE,to.data.frame=FALSE)
data_frame<-as.data.frame(data)
dim(data_frame)
# Variable Labels...
variable_labels <- attr(data, "variable.labels")
variable_labels
# Value Labels...
value_labels<-attr(data,"label.table")
value_labels