[R] if else statement adjustemtn

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Sat Jun 13 02:46:02 CEST 2020


Hello

I have a data frame like this:

> head(b)
       FID   IID FLASER PLASER
1: fam1000 G1000      1      1
2: fam1001 G1001      1      1
3: fam1003 G1003      1      2
4: fam1005 G1005      1      1
5: fam1009 G1009      1      1
6: fam1052 G1052      1      1
...

> table(b$PLASER,b$FLASER, exclude = NULL)

         1   2   3 <NA>
  1    836  14   0    0
  2    691  70  43    2
  3      2   7  21    0
  <NA>   4   1   0    7

I am trying to make a new column "pheno" so that I reduce the number of NAs

right now I am doing:

> b$pheno=ifelse(b$PLASER==2 | b$FLASER==2,2,1)
> table(b$pheno, exclude = NULL)

   1    2 <NA>
 859  828   11

I would like to reduce this number of NAs to be 7
so I would like to have in "pheno column"
7 NAs
825 2s (825=691+14+70+7+43)
and the rest would be 1s (866=1698-7-825)

How can I change the above command to get these numbers?

Thanks
Ana



More information about the R-help mailing list