Re: [R] how to change automatically 0=no and 1=yes

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 16 Jun 2005 - 09:34:59 EST

One thing to be careful of is that we likely intend to represent the columns of the data frame as factors in which case we still want the levels to be No and Yes even if a column only consists of one level (i.e. all No or all Yes). Note that one solution specifically provided for that.

On 6/15/05, Muhammad Subianto <subianto@gmail.com> wrote:
> Dear all,
> Sean Davis, Dimitris Rizopoulos and Marc Schwartz, thanks for your great
> help. It works perfectly. Thanks a lot.
> All the best,
> Muhammad Subianto
>
> On this day 6/15/2005 4:06 PM, Sean Davis wrote:
> > > x <- data.frame(matrix(c(1,0,1,0,1,1),nrow=3))
> > > x[x==0] <- 'no'
> > > x[x==1] <- 'yes'
> > > x
> > X1 X2
> > 1 yes no
> > 2 no yes
> > 3 yes yes
> >
>
> On this day 6/15/2005 4:06 PM, Dimitris Rizopoulos wrote:
> > try this:
> >
> > dat <- data.frame(matrix(sample(0:1, 100 * 20, TRUE), 100, 20))
> > ############
> > dat[] <- lapply(dat, factor, levels = c(0, 1), labels = c("no",
> > "yes"))
> > dat
> >
>
> On this day 6/15/2005 4:16 PM, Marc Schwartz wrote:
> >
> >
> >>as.data.frame(ifelse(df == 0, "No", "Yes"))
> >
>
>
> On this day 6/15/2005 3:58 PM, Muhammad Subianto wrote:
> > Dear R-helpers,
> > I have dataset (data.frame) like below,
> > x1 x2 x3 x4 x5 x6 x7 x8 x9 ... x1200
> > 0 0 0 1 1 0 0 1 1
> > 1 0 0 1 1 0 0 1 1
> > 0 1 0 1 1 0 0 1 1
> > 1 1 0 1 1 0 0 1 1
> > ...
> > How can I change automatically 0=no and 1=yes.
> >
> > Thank you very much in advance.
> > Kindly regards,
> > Muhammad Subianto
> >
> > ______________________________________________
> > R-help@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
> >
>
> ______________________________________________
> R-help@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
>



R-help@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 Received on Thu Jun 16 09:44:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:43 EST