[R] how to create a new column with conditions
Rasmus Liland
jen@r@@mu@ @end|ng |rom gm@||@com
Wed Apr 8 23:33:52 CEST 2020
On April 8, 2020 1:17:38 PM PDT, Ana Marija wrote:
| Hi,
|
| I have a data frame like this:
Or ... *drum-roll* ... you could use plain
old indexing. Have a look:
a <-
"FID LASER2 CURRELIG PLASER RTNPTHY
fam1000_G1000 1 1 1 1
fam1001_G1001 1 1 1 1
fam1003_G1003 2 1 2 2
fam1005_G1005 1 1 1 2
fam1009_G1009 1 1 1 2
fam1052_G1052 1 1 1 2"
a <- read.delim(text=a)
a$PHENO <- -9
a[a$CURRELIG==1 & a$RTNPTHY==1,"PHENO"] <- 1
a[a$PLASER==2,"PHENO"] <- 2
Best,
Rasmus
More information about the R-help
mailing list