Re: [R] Help with write.csv

From: <>
Date: Mon, 11 Feb 2008 09:37:33 +0000

> 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
> 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,
> :
> 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:


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.


Mathematical Sciences Unit

ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 11 Feb 2008 - 09:49:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Feb 2008 - 10:30:12 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive