An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091124/27851110/attachment-0001.pl>
How to identify the rows in my dataframe with a negative value in any column?
5 messages · Mark, Henrique Dallazuanna, Steve Lianoglou +1 more
Try this: DF[rowSums(DF < 0) == 0,]
On Tue, Nov 24, 2009 at 5:58 PM, Mark Na <mtb954 at gmail.com> wrote:
Dear R-helpers, I have a dataframe that should not contain any negative values, but it does. I wish to print the rows from my dataframe that contain a negative value in any column. I've tried this:
dataframe[dataframe<0,]
but it just returns a row of NAs. I would very much appreciate any help with this you could provide. Thanks, Mark ? ? ? ?[[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.
Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi,
On Nov 24, 2009, at 2:58 PM, Mark Na wrote:
Dear R-helpers, I have a dataframe that should not contain any negative values, but it does. I wish to print the rows from my dataframe that contain a negative value in any column. I've tried this:
dataframe[dataframe<0,]
but it just returns a row of NAs. I would very much appreciate any help with this you could provide.
Imagine you had a data.frame like this: R> df <- data.frame(a=1:10, b=c(1:3,-4, 5:10), c=c(-1, 2:10)) This will return you a boolean vector of which rows have negative values: R> has.neg <- apply(df, 1, function(row) any(row < 0)) If you want the actually index numbers: R> which(has.neg) [1] 1 4 HTH, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091124/7b11c2d8/attachment-0001.pl>
On Nov 24, 2009, at 3:04 PM, Henrique Dallazuanna wrote:
Try this: DF[rowSums(DF < 0) == 0,]
ITYM: > DF <- data.frame(a=1:10, b=c(1:3,-4, 5:10), c=c(-1, 2:10)) > > DF[rowSums(DF < 0) > 0,] a b c 1 1 1 -1 4 4 -4 4 -- David
On Tue, Nov 24, 2009 at 5:58 PM, Mark Na <mtb954 at gmail.com> wrote:
Dear R-helpers, I have a dataframe that should not contain any negative values, but it does. I wish to print the rows from my dataframe that contain a negative value in any column. I've tried this:
dataframe[dataframe<0,]
but it just returns a row of NAs. I would very much appreciate any help with this you could provide. Thanks, Mark
David Winsemius, MD Heritage Laboratories West Hartford, CT