Hi Ana,
The ifelse function works like this:
*ifelse(condition, if.true, if.false)*
it will check the condition, and if, and only if, condition is true, it
will execute whatever is in if.true,
and if condition is false (and only if the condition is false) it will
execute what's in if.false.
wh
Hi
instead of complicated ifelse construction I would try perform the task in
several steps
# make a new column
test$new <- NA
# select CURRELIG and RTNPTHY and set new to 1
test$new[which(test$CURRELIG==1 & test$RTNPTHY==1)] <- 1
# select CURRELIG and PLASER and set new to 2
test$new[which(te
Hello Ana Marija,
Apologies, the warning escaped me. When Pheno is assigned NA .
> a=a[,PHENO:=NA]
It is assigned a NA of type logical by default. We just have to make
sure it is an NA of type numeric
> a[,PHENO:=1.0*NA]
So the full set of commands is:
library(data.table)
setDT(a)
a[,PHENO:=
Hi Jeremie,
when I try to reproduce your code this is what I get:
> a=setDT(a)
> head(a)
FID IID CURRELIG PLASER RTNPTHY
1: fam0110 G1102 2 2
2: fam0113 G1132 2 2
3: fam0114 G1142 2 2
4: fam0117 G1172 2 2
5: fam01
Hello Ana Marija,
I cannot reproduce your error,
with a$PHENO=ifelse(a$PLASER==2 |a$RTNPTHY==2, 2, ifelse(a$CURRELIG==1 |
a$RTNPTHY==1,1,NA))
For instance I have the expected PHENO=2
> FID IID CURRELIG PLASER RTNPTHY PHENO
> 39: fam5706 G57061 1 2 2
In gen
Nested ifelse()'s are confusing and invite error.
Just use ?within and subscript with your conditions:
dat$PHENO <- NA ## initialize PHENO
> dat <- ## to return the modified result
within(dat, {
+ PHENO[CURRELIG ==1] <- 1
+ PHENO[CURRELIG == 1 & PLASER == 2] <- 2
+ PHENO[CURRELIG ==
I tried doing this:
a$PHENO=ifelse(a$PLASER==2 | a$RTNPTHY==2,2,ifelse(a$CURRELIG==1 |
a$RTNPTHY==1,1,NA))
which brought be closer to the solution, but now I have lines like this:
FID IID CURRELIG PLASER RTNPTHY PHENO
fam3151 G31511 1 NANA
fam3149 G31492
7 matches
Mail list logo