RE: [R] count element in column

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Thu 06 Jan 2005 - 05:15:56 EST


....

> How about this?
> length(res[res < 0, 1])
> HTH, Andy
>
or simply sum(res<0) .

For R beginners: This works because the logical res<0 vector is automatically coerced to a numeric vector of 0's and 1's by sum().

> > -----Original Message-----
> > From: r-help-bounces@stat.math.ethz.ch
> > [mailto:r-help-bounces@stat.math.ethz.ch]On Behalf Of
> Frederic renaud
> > Sent: Wednesday, January 05, 2005 11:08 AM
> > To: r-help@stat.math.ethz.ch
> > Subject: [R] count element in column
> >
> >
> > Hi,
> > I 've a matrix n*1 (thus a column) and I would like to
> > count the number of negative element inside.
> > Can you help me?
> > Thanks!
> >
> > eg:
> > res[,1]= 1
> > -3
> > -1
> >
> > How obtain the number 2 (number of negative-element)?
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> >
https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jan 06 05:25:11 2005

This archive was generated by hypermail 2.1.8 : Thu 06 Jan 2005 - 06:15:34 EST