Thanks Steve, this works very well!

Mark



On Tue, Nov 24, 2009 at 2:07 PM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

> 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<http://cbio.mskcc.org/%7Elianos/contact>
>
>


-- 
Mark Na
University of Saskatchewan
Saskatoon, Canada

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to