[R] if else statement adjustemtn
Rasmus Liland
jr@| @end|ng |rom po@teo@no
Sat Jun 13 04:28:37 CEST 2020
On 2020-06-13 11:30 +1000, Jim Lemon wrote:
> On Fri, Jun 12, 2020 at 8:06 PM Jim Lemon wrote:
> > On Sat, Jun 13, 2020 at 10:46 AM Ana Marija wrote:
> > >
> > > I am trying to make a new column
> > > "pheno" so that I reduce the number
> > > of NAs
> >
> > it looks like those two NA values in
> > PLASER are the ones you want to drop.
>
> From just your summary table, it's hard to
> guess the distribution of NA values.
Dear Ana,
This small sample
b <- read.table(text="FLASER;PLASER
1;2
;2
;
1;
2;
2;2
3;2
3;3
1;1", sep=";", header=TRUE)
table(b$PLASER,b$FLASER, exclude = NULL)
yields the same combinations you showed
earlier:
1 2 3 <NA>
1 1 0 0 0
2 1 1 1 1
3 0 0 1 0
<NA> 1 1 0 1
If you want to eliminate the four <NA>-based
combinations completely, this line
b$pheno <-
ifelse(b$PLASER==2 |
b$FLASER==2 |
is.na(b$PLASER) |
is.na(b$PLASER) & b$FLASER %in% 1:2 |
is.na(b$FLASER) & b$PLASER == 2,
2, 1)
table(b$pheno, exclude = NULL)
will do it:
1 2
2 7
Best,
Rasmus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200613/40a643bb/attachment.sig>
More information about the R-help
mailing list