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
2 2 2 NA
19 fam5658 G56581 1 1 1
20 fam5659 G56592 2 2 NA
Cheers
Petr
> -Original Message-
> From: R-help On Behalf Of Ana Marija
> Sent: Wednesday, September 23, 2020 6:44 PM
> To: r-help
> Subject: [R] help with ne
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
Hello,
I have a data frame as shown bellow.
I want to create a new column PHENO which will be defined as follows:
if CURRELIG==1 -> PHENO==1
in the above subset those that have:
PLASER==2 -> PHENO==2
and
those where RTNPTHY==1 -> PHENO==1
I tried doing this:
a$PHENO=ifelse(a$CURRELIG==1 | a$RTNPT
Hello,
This is cross-posted from
https://stackoverflow.com/questions/47042591/how-to-resolve-nested-variables-inside-a-loop-in-r
And you already have the answer there. See my comment.
Rui Barradas
Em 31-10-2017 19:00, Edward Guda via R-help escreveu:
How do i resolve this?
symbol <- c('RRR
R does not look inside strings for language objects like your symbol variable.
Nor does it magically figure out that it needs to keep previous values in a
loop. And you need to be able to use valid syntax to ask clear questions in
this list, so some more time with a tutorial should occur before
How do i resolve this?
symbol <- c('RRR' ,'GGG')
for(i in seq_along(symbol)) {
dat <- Quandl("LLL/symbol[i]")
}
required solutionis a loop where Quandl is a function and it loops as flows,
Quandl("LLL/RRR")
Quandl("LLL/GGG")
__
R-help@r-project
11 matches
Mail list logo