[R] removing the columns with 0 or NA or 1or NA or 2 or NA
Lida Zeighami
lid.zigh at gmail.com
Thu Jul 16 16:58:25 CEST 2015
I have ma matrix which its elements are NA,0,1,2 ! I got my answer bout
removing the columns with 0 or NA or both values but now I want to add
additional condition for deleting the columns! I have to delete the columns
which contain the same value. delete the columns with NA or 0 or both and
the columns with NA or 1 or both and the column with NA or 2 or both (I
should keep the columns which have variation in their values)! I use this
code but didn't work properly:
mat_nonNA<- mat[, !apply((is.na(mat) | mat == 0) & (is.na(mat) | mat==1) &(
is.na(mat) | mat==2), 2, all)]
mat
1:110590170 1:110888172 1:110906406 1:110993854
1:110996710 1:111144756
A05363 1 1 1
2 NA
0
A05370 0 1
0 NA 0 NA
A05380 1
NA 2 NA
NA
0
A05397 0 1
0 NA 0 2
A05400 2 1
0 2 0 0
A05426
0 NA NA NA
0 1
my out put should be like below:
1:110590170 1:110906406 1:111144756
A05363 1 1
0
A05370 0 0
NA
A05380 1 2
0
A05397 0
0 2
A05400 2 0
0
A05426 0 NA
1
Thanks for your help
[[alternative HTML version deleted]]
More information about the R-help
mailing list