Skip to content

longitudinal study

1 message · arun

#
Hi Bibek,

You can do this in different ways:
set.seed(15)
dat1<-as.data.frame(matrix(sample(c("Yes","No"),20,replace=TRUE),ncol=5),stringsAsFactors=FALSE)
dat1[dat1=="Yes"]<-1
dat1[dat1=="No"]<-0
dat1[]<- sapply(dat1,as.numeric)

?dat1
# ?V1 V2 V3 V4 V5
#1 ?0 ?1 ?0 ?0 ?1
#2 ?1 ?0 ?0 ?0 ?0
#3 ?0 ?0 ?1 ?0 ?1
#4 ?0 ?1 ?0 ?0 ?0

#or
set.seed(15)
?dat2<-as.data.frame(matrix(sample(c("Yes","No"),20,replace=TRUE),ncol=5),stringsAsFactors=TRUE)
dat2[]<-sapply(dat2,as.numeric)-1
?dat2
# ?V1 V2 V3 V4 V5
#1 ?0 ?1 ?0 ?0 ?1
#2 ?1 ?0 ?0 ?0 ?0
#3 ?0 ?0 ?1 ?0 ?1
#4 ?0 ?1 ?0 ?0 ?0
?identical(dat1,dat2)
#[1] TRUE


A.K.


----- Original Message -----
From: bibek sharma <mbhpathak at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: 
Sent: Monday, February 4, 2013 12:54 PM
Subject: Re: [R] longitudinal study

Dear Arun,

I have a data set with dim 1200 by 56 where the variable has binomial
response ( yes or no). I want to replace all the "yes" by 1 and "no"by
0 in the entire data set. is there any sort cut way of recoding?
Thank in advance for your help.
Bibek
On Fri, Jan 18, 2013 at 11:54 AM, arun <smartpink111 at yahoo.com> wrote: