[R] Help with write.csv
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Mon Feb 11 10:37:33 CET 2008
> I am new to R. I am using the impute package with data contained in csv
> file.
> I have followed the example in the impute package as follows:
>
> > mydata = read.csv("sample_impute.csv", header = TRUE)
> > mydata.expr <- mydata[-1,-(1:2)]
> > mydata.imputed <- impute.knn(as.matrix(mydata.expr))
>
> The impute is succesful.
>
> Then I try to write the imputation results (mydata.imputed) to a csv
file
> such as follows..
>
> > write.csv(mydata.imputed, file = "sample_imputed.csv")
> Error in data.frame(data = c(-0.07, -1.22, -0.09, -0.6, 0.65, -0.36,
0.25,
> :
> arguments imply differing number of rows: 18, 1, 0
When you use write.csv, the object that you are writing to a file must
look something like a data frame or a matrix, i.e. a rectangle of data.
The error message suggests that different columns of the thing you are
trying to write have different numbers of rows.
This means that mydata.imputed isn't the matrix it is supposed to be.
You'll have to do some detective work to figure out what mydata.imputed
really is. Try this:
mydata.imputed
class(mydata.imputed)
dim(mydata.imputed)
Then you need to see why mydata.imputed isn't a matrix. Here there are
two possibilities
1. There are some lines of code that you didn't tell us about, where you
overwrote mydata.imputed with another value.
2. The impute wasn't as successful as you thought.
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}
More information about the R-help
mailing list