[R] Select only rows that don't contain one number

Farhan Ahmed farhan at farhan.org
Tue Jul 30 16:17:21 CEST 2013


  x[!apply(x, 1, function (y) any(y==-1)),]

------ Original Message ------
From: "Dimitri Liakhovitski" <dimitri.liakhovitski at gmail.com>
To: "r-help" <r-help at r-project.org>
Sent: 7/30/2013 10:06:02 AM
Subject: [R] Select only rows that don't contain one number
>Hello!
>
>I have a data frame:
>
>x<-data.frame(a=c(-1,1,2,3,4),b=c(1,-1,3,4,5),c=1:5,d=2:6,e=c(1,2,3,-1,4))
>x
>
>How can I grab only those rows that don't contain any -1s (no matter in
>what columns? Without writing a loop.
>In other words, I want my output to contain only rows 3 and 5 of x.
>
>Thank you very much!
>
>  [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide 
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list