> -----Original Message-----
> From:
[hidden email]
> [mailto:
[hidden email]] On Behalf Of esawdust
> Sent: Tuesday, September 01, 2009 8:53 AM
> To:
[hidden email]
> Subject: [R] Simple question about error on CSV import
>
>
>
> I have a substantial CSV to import but can't seem to import even the
> simplest CSV.
>
> I'm running the latest stable REvolution R on OS X if that is
> pertinent.
>
> Here's the contents of a simple test2.csv CSV file:
>
> #,Status,Project
> 5842,New,Test
>
> > snortalerts = read.table(
> "/Users/lcox/Documents/test2.csv", header=TRUE,
> > sep=",", row.names="#")
> Error in data[[rowvar]] : attempt to select less than one element
>
> I can't see how it could get any more simple, yet it doesn't
> work. I'm
> obviously missing something basic, but based on the error, I
> can't see what
> it is.
Using '#' for the initial column name presents 2 problems:
(a) # is the default comment character so that line is
ignored. Add the read.table argument comment.char=""
to take care of that.
(b) It looks like the column names are converted to legal
R names before the row.names="name" is processed
and the "#" is not legal so it becomes something random
like "X.". If you turn off this conversion to legal names
with check.names=FALSE then things will work. It
might be better to use the index of the row.names column
instead of the name, as in row.names=1.
E.g.,
> t<-"#,Status,Project\n5842,New,Test\n"
> read.table(textConnection(t), header=TRUE, sep=",", comment.char="",
check.names=FALSE, row.names="#")
Status Project
5842 New Test
> read.table(textConnection(t), header=TRUE, sep=",", comment.char="",
row.names=1)
Status Project
5842 New Test
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide
http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.