[R] Odp: R not recognizing words

Petr PIKAL petr.pikal at precheza.cz
Fri Jan 6 09:03:59 CET 2012


Hi
> 
> Hello all
> 
> I'm new to R and am experiencing a problem with a categorical variable. 
All
> the data of this variable are "Low", "High", or NA.  When I put
> summary(x$y), it gives me the number of High, Low, and NA entries. 
However,
> when I try to subset by writing     x$y=="Low"  or x$y=="High", R does 
not
> recognize the word and it writes FALSE for all the entries (but not the 
NA
> entries). 
> 
> Can anybody help me out?

You are not telling the whole story

x<- sample(c("Low", "High"), 20, replace=T)
> x
 [1] "Low"  "Low"  "Low"  "High" "Low"  "Low"  "Low"  "Low"  "Low"  "High"
[11] "Low"  "High" "High" "Low"  "Low"  "High" "Low"  "Low"  "High" "Low" 
> x[5:7] <- NA
> x<-data.frame(y=x)
> x$y=="Low"
 [1]  TRUE  TRUE  TRUE FALSE    NA    NA    NA  TRUE  TRUE FALSE  TRUE 
FALSE
[13] FALSE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE

> x[x$y=="Low",]
 [1] Low  Low  Low  <NA> <NA> <NA> Low  Low  Low  Low  Low  Low  Low  Low 
Levels: High Low

Works as expected. So probably your expectation is wrong.

Regards
Petr




> 
> Thanks
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/R-not-
> recognizing-words-tp4268283p4268283.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list