OK, so this is a really stupid question and should be incredibly simple to do but I can't figure it out. So maybe someone would be so kind as to tell me. I have a vector of zeros and ones. I want to replace all of the zeros with "black" and all of the ones with "gray". That's it. Any help would be appreciated. Thanks, Paul `-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. `=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/ `=` >==/ >==/ >==/ >==/ >==/ ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=, ,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' Paul Lepp, Ph.D. Stanford School of Medicine VAPAHCS, 154T Dept. of Microbiology & Immunology 3801 Miranda Ave Stanford University Palo Alto, CA 94304 Stanford, CA (650) 493-5000 x66762 fax: (650) 852-3291 http://cmgm.stanford.edu/~pwlepp pwlepp at cmgm.stanford.edu
ifelse(x == 0, "black", "gray") --sundar Paul Lepp wrote:> OK, so this is a really stupid question and should be incredibly simple to > do but I can't figure it out. So maybe someone would be so kind as to tell > me. > I have a vector of zeros and ones. I want to replace all of the zeros with > "black" and all of the ones with "gray". That's it. Any help would be > appreciated. > > Thanks, > Paul > > `-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. > `=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/ `=` > >==/ >==/ >==/ >==/ >==/ > ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=, > ,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' > Paul Lepp, Ph.D. Stanford School of Medicine > > VAPAHCS, 154T Dept. of Microbiology & Immunology > 3801 Miranda Ave Stanford University > Palo Alto, CA 94304 Stanford, CA > (650) 493-5000 x66762 fax: (650) 852-3291 > http://cmgm.stanford.edu/~pwlepp pwlepp at cmgm.stanford.edu > > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Thu, 7 Oct 2004, Paul Lepp wrote:> OK, so this is a really stupid question and should be incredibly simple to > do but I can't figure it out. So maybe someone would be so kind as to tell > me. > I have a vector of zeros and ones. I want to replace all of the zeros with > "black" and all of the ones with "gray". That's it. Any help would be > appreciated. >You can do this with yournewvector <- ifelse(yourvector == 1, "black", "gray") but you may actually want to create a factor yournewvector <- factor(youroldvector, labels=c("gray", "black")) -thomas
"Paul Lepp" <pwlepp at pmgm2.stanford.edu> writes:> OK, so this is a really stupid question and should be incredibly simple to > do but I can't figure it out. So maybe someone would be so kind as to tell > me. > I have a vector of zeros and ones. I want to replace all of the zeros with > "black" and all of the ones with "gray". That's it. Any help would be > appreciated.v2 <- ifelse(v==0,"black","gray") or v2 <- c("black","gray")[v+1] -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907