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? 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.
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 doesnot> recognize the word and it writes FALSE for all the entries (but not theNA> 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On Jan 6, 2012, at 06:20 , arabarkev wrote:> 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?Trailing whitespace? Check levels(x$y)> > 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
There was a trailing white space! Now I feel not so smart Thanks a lot for your help! -- View this message in context: http://r.789695.n4.nabble.com/R-not-recognizing-words-tp4268283p4269326.html Sent from the R help mailing list archive at Nabble.com.
I've developed a preference for x$y %in% "Low" when subsetting. ? Benjamin Nutter |??Biostatistician ? |??Quantitative Health Sciences ? Cleveland Clinic? | ?9500 Euclid Ave.? | ?Cleveland, OH 44195? |?(216) 445-1365 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of arabarkev Sent: Friday, January 06, 2012 12:20 AM To: r-help at r-project.org Subject: [R] R not recognizing words 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? 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. ================================== Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News & World Report (2010). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}}