Hi, I am reading in a dataframe from a CSV file. It has 70 columns. I do not have any kind of unique "row id". rawdata <- read.table("r_work/train_data.csv", header=T, sep=",", na.strings=0) When training an svm, I keep getting an error So, as an experiment, I wrote the data back out to a new file so that I could see what the svm function sees. write.table(rawdata, file="r_work/output_data.csv", quote=FALSE, sep=",") It appears as if R has added a column for me with id numbers for each row. That would be fine, except that R SHIFTS ALL MY COLUMN LABELS OVER ONE. That causes several problems: 1) The header names are now wrong for each column 2) My last column has no label 3) The SVM complains about the unlabeled column Would someone please help me sort this out. Thanks! -N [[alternative HTML version deleted]]
try 'row.names=FALSE' in the write.table. On Sun, Aug 2, 2009 at 5:10 PM, Noah Silverman<noah at smartmediacorp.com> wrote:> Hi, > > I am reading in a dataframe from a CSV file. ?It has 70 columns. ?I do > not have any kind of unique "row id". > > > rawdata <- read.table("r_work/train_data.csv", header=T, sep=",", > na.strings=0) > > When training an svm, I keep getting an error > > So, as an experiment, I wrote the data back out to a new file so that I > could see what the svm function sees. > > write.table(rawdata, file="r_work/output_data.csv", quote=FALSE, sep=",") > > > It appears as if R has added a column for me with id numbers for each > row. ?That would be fine, except that R SHIFTS ALL MY COLUMN LABELS OVER > ONE. ?That causes several problems: > ? ? 1) The header names are now wrong for each column > ? ? 2) My last column has no label > ? ? 3) The SVM complains about the unlabeled column > > Would someone please help me sort this out. > > Thanks! > > -N > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On 02-Aug-09 21:10:12, Noah Silverman wrote:> Hi, > I am reading in a dataframe from a CSV file. It has 70 columns. > I do not have any kind of unique "row id". > > rawdata <- read.table("r_work/train_data.csv", header=T, sep=",", > na.strings=0) > > When training an svm, I keep getting an error > So, as an experiment, I wrote the data back out to a new file > so that I could see what the svm function sees. > > write.table(rawdata, file="r_work/output_data.csv", > quote=FALSE, sep=",") > > It appears as if R has added a column for me with id numbers > for each row. That would be fine, except that R SHIFTS ALL MY > COLUMN LABELS OVER ONE. That causes several problems: > 1) The header names are now wrong for each column > 2) My last column has no label > 3) The SVM complains about the unlabeled column > > Would someone please help me sort this out. > Thanks! > -NNot that the default for "row.names" in write.table() is TRUE. So. in your caoomand, that is what you get. write.table() then *creates* row-names (by default the row numbers). Compare: D <- rbind(c(1.1,1.2,1.3),c(2.1,2.2,2.3),c(3.1,3.2,3.3)) D # [,1] [,2] [,3] # [1,] 1.1 1.2 1.3 # [2,] 2.1 2.2 2.3 # [3,] 3.1 3.2 3.3 write.table(D,file="withTRUE.csv",quote=FALSE,sep=",") # withTRUE.csv: # V1,V2,V3 # 1,1.1,1.2,1.3 # 2,2.1,2.2,2.3 # 3,3.1,3.2,3.3 write.table(D,file="withFALSE.csv",row.names=FALSE,quote=FALSE,sep=",") # withFALSE.csv: # V1,V2,V3 # 1.1,1.2,1.3 # 2.1,2.2,2.3 # 3.1,3.2,3.3 Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 02-Aug-09 Time: 22:35:04 ------------------------------ XFMail ------------------------------