On Nov 10, 2011, at 8:41 AM, Sarah Goslee wrote:
Without having any actual idea what you mean (sample data!), this
might work:
sex <- c(1,0,1,0)
sex1 <- c(1,1,0,0)
samesex <- ifelse(sex == 1 & sex1 == 1, 1, 0)
> sex & sex1
[1] TRUE FALSE FALSE FALSE
> 0+(sex & sex1)
[1] 1 0 0 0
Note t
Re: [R] Creating dummys in R
Without having any actual idea what you mean (sample data!), this might work:
sex <- c(1,0,1,0)
sex1 <- c(1,1,0,0)
samesex <- ifelse(sex == 1 & sex1 == 1, 1, 0)
Note that this does NOT return 1 if both initial variables are 0, so
it isn't really a s
Hi,
Try ifelse function.
samesex <- ifelse( sex==1 & sex1==1, yes=1, no=0)
Cheers
Philippe Baril Lecavalier
On 2011-11-10 8:03 AM, "David ." wrote:
>
> Dear R-project!
>
> How do i create 1 dummy from 2 already existing dummys. To be more
> precise, I want to create a dummy from a dummy calle
Without having any actual idea what you mean (sample data!), this might work:
sex <- c(1,0,1,0)
sex1 <- c(1,1,0,0)
samesex <- ifelse(sex == 1 & sex1 == 1, 1, 0)
Note that this does NOT return 1 if both initial variables are 0, so
it isn't really a samesex indicator, but it is my best guess as to
Not sure what you mean by 'dummies'; do you mean 'objects'?
samesex <- sex == sex1
Examples of the data would help in the formulation of an answer.
On Thu, Nov 10, 2011 at 5:13 AM, David . wrote:
>
> Dear R-project!
>
> How do i create 1 dummy from 2 already existing dummys. To be more precise,
Dear R-project!
How do i create 1 dummy from 2 already existing dummys. To be more precise, I
want to create a dummy from a dummy called "sex" and another called "sex1" when
both thoose dummys are 1 I want my created dummy "samesex" to take 1.
Thanks for the help!
Paulie
6 matches
Mail list logo