Skip to content
Prev 387596 / 398502 Next

Thanks for help

Okay, if I understand this, you want to remove all rows that have, for
example, a 1 in any of ten columns:

a<-matrix(sample(1:20,350,TRUE),ncol=10)
# check it out
a
# first do it with a loop
b<-a
for(i in 1:ncol(b)) b<-b[b[,i]!=1,]
b
# now get tricky and do it in one operation
no1s<-apply(a,1,function(x) any(1 %in% x))
no1s
[1]  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
FALSE
[25]  TRUE FALSE  TRUE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE
c<-a[!no1s,]
c

Jim
On Fri, Mar 26, 2021 at 8:17 AM Goyani Zankrut <zankrut20 at gmail.com> wrote: