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@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. ______________________________________________ R-help@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.