[R] Why can't I access this type?
Bert Gunter
gunter.berton at gene.com
Sun Mar 22 16:15:03 CET 2015
Your data frame contains no column named "Name" .
Maybe what you want is
rownames(all.states)[all.state$Frost>150]
However, what you clearly need to do is stop posting until you have
done your homework by spending some time with one of the many good R
tutorials that are out there (possibly Intro to R, which ships with R,
though it's getting a bit dated now). This appears to be a very basic
question. If you are going through a tutorial and got stuck here, then
note that row names are an attribute of the data frame, not a column
name of one of its columns. See ?rownames and the links therein for
more info.
Cheers,
Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Sun, Mar 22, 2015 at 7:39 AM, Yves S. Garret
<yoursurrogategod at gmail.com> wrote:
> Hi, I'm just learning my way around R. I got a bunch of states and would
> like to access to get all of the ones where it's cold. But when I do the
> following, I will get the following error:
>
>> all.states <- as.data.frame(state.x77)
>> cold.states <- all.states[all.states$Frost > 150, c("Name", "Frost")]
> Error in `[.data.frame`(all.states, all.states$Frost > 150, c("Name", :
> undefined columns selected
>
> I don't get it. When I look at all.states, this is what I see:
>
>> str(all.states)
> 'data.frame': 50 obs. of 8 variables:
> $ Population: num 3615 365 2212 2110 21198 ...
> $ Income : num 3624 6315 4530 3378 5114 ...
> $ Illiteracy: num 2.1 1.5 1.8 1.9 1.1 0.7 1.1 0.9 1.3 2 ...
> $ Life Exp : num 69 69.3 70.5 70.7 71.7 ...
> $ Murder : num 15.1 11.3 7.8 10.1 10.3 6.8 3.1 6.2 10.7 13.9 ...
> $ HS Grad : num 41.3 66.7 58.1 39.9 62.6 63.9 56 54.6 52.6 40.6 ...
> $ Frost : num 20 152 15 65 20 166 139 103 11 60 ...
> $ Area : num 50708 566432 113417 51945 156361 ...
>
> What am I messing up?
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
More information about the R-help
mailing list