Hi,
I have a file like this:
> head(aa)
PLASER CURRELIG RTNPTHY
1 1 1 1
2 1 1 1
3 2 1 2
4 1 1 2
5 1 1 2
6 1 1 2
I have to create another column, say "new" which will satisfy these conditions:
PLASER=2 AND CURRELIG=1 -> new=2
RTNPHY=1 AND CURRELIG=1 -> new=1
I tried running this command:
aa$new <- ifelse(aa$CURRELIG==1 & aa$PLASER==2, 2, ifelse(aa$CURRELIG==1 & aa$RTNPHY==1,1,NA))
but I am getting this output which is not correct:
> head(aa)
PLASER CURRELIG RTNPTHY new
1 1 1 1 NA
2 1 1 1 NA
3 2 1 2 2
4 1 1 2 NA
5 1 1 2 NA
6 1 1 2 NA
Can someone please help with this?
Thanks ANA
So I did why you posted above and when I do:
why do total count of "1" and "2" exceed to number of entries in this data frame?
This is wrong, where is the condition to check
"RTNPTHY"
column?Apologies for the Typo, I misread column names in the OP, I've edited my answer.