[R] error when extracting from a data frame
Suzanne.mertens
suzanne.mertens at gmail.com
Tue Jan 17 22:17:41 CET 2012
(As a noob to R, this is my first posting - yes yes, groans all around...)
I'm trying to extract certain rows from a data frame. I used the following to import data from a CSV txt file.
data <- read.table(file="data.txt", header=TRUE)
when I do this, my attempt to extract the data rows only from where the Station value equals 1…
data.station1 <- data[data$Station == 1]
...is giving me the following error message:
Error in `[.data.frame`(data, data
$Station == 1) :
undefined columns selected
Bah.
If I use names(data) I can see "Station" as a column name.
And if I use str(data), the variable "Station" is coming up as integers including the value 1.
And if I use data$Station, I see all station values, including the 1s.
And if I use data[,"Station"] I do see all the Station values
And if I instead treat the Station values as characters, by using "1", I still get the "undefined" error.
Could someone please correct me on my syntax? Or advise if perhaps I imported the data the wrong way? I'm working out of "A Beginner's Guide to R" and also looked through the R manual, and even tried this from Google search:
data.station1 <- data,("Station" == 1) ]
But that gave me an unwanted output:
data frame with 0 columns and 789 rows
Almost, but not quite. Please help?
Thank you,
- Suzanne
..........................................
suzanne.mertens at gmail.com
404-337-1533
More information about the R-help
mailing list