I'd like to add metadata to my spreadsheet as comments, and have R ignore these afterwards.
My data are of the form
v1,v2,v3,
1,5,7,
4,2,1,#possible error,
(which the exception that it is much longer. the first comment actually appears well outside of the top 5 rows, used by scan
to determine the number of columns)
I've been trying:
read.table("data.name",header=TRUE,sep=",",stringsAsFactors=FALSE,comment.char="#")
But read.table
(and, for that matter, count.fields
) thinks that I have one more field than I actually do. My data frame ends up with a blank column called 'X'. I think this is because my spreadsheet program adds commas to the end of every line (as in the above example).
Using flush=TRUE
has no effect, even though (according to the help file) it " [...] allows putting comments after the last field [...]"
Using colClasses=c(rep(NA,3),NULL)
has no effect either.
I could just delete the column afterwards, but since it seems that this is a common practice I'd like to learn how to do it properly.
Thanks,
Andrew