Hi there, I have a data set: a=cbind(5,2,4,7,8,3,4,11,1,20) I want to count # of data, satistfying a[1]<a[2:10]. Anyone helps me solving this case? Thank you in advance, Jin -- View this message in context: http://www.nabble.com/count-data-with-some-conditions-tp20275722p20275722.html Sent from the R help mailing list archive at Nabble.com.
Do you want the count of remaining elements which are strictly greater than the first element? > length(which(a[1] < a[2:10])) [1] 4 or perhaps a bit more deviously: > sum( a[1]<a[2:10]+0 ) #adding 0 to TRUE or FALSE creates 1 or 0. [1] 4 -- David Winsemius, MD Heritage Labs. On Oct 31, 2008, at 7:56 PM, sandsky wrote:> > Hi there, > > I have a data set: > > a=cbind(5,2,4,7,8,3,4,11,1,20) > > I want to count # of data, satistfying a[1]<a[2:10]. > > Anyone helps me solving this case? > > Thank you in advance, > > > Jin > -- > View this message in context: http://www.nabble.com/count-data-with-some-conditions-tp20275722p20275722.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
David, Yes, it is what I want. It is a great help. Thank you, Jin David Winsemius wrote:> > Do you want the count of remaining elements which are strictly > greater than the first element? > > > length(which(a[1] < a[2:10])) > [1] 4 > > or perhaps a bit more deviously: > > > sum( a[1]<a[2:10]+0 ) #adding 0 to TRUE or FALSE creates 1 or 0. > [1] 4 > > -- > David Winsemius, MD > Heritage Labs. > > On Oct 31, 2008, at 7:56 PM, sandsky wrote: > >> >> Hi there, >> >> I have a data set: >> >> a=cbind(5,2,4,7,8,3,4,11,1,20) >> >> I want to count # of data, satistfying a[1]<a[2:10]. >> >> Anyone helps me solving this case? >> >> Thank you in advance, >> >> >> Jin >> -- >> View this message in context: >> http://www.nabble.com/count-data-with-some-conditions-tp20275722p20275722.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> 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. > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/count-data-with-some-conditions-tp20275722p20277774.html Sent from the R help mailing list archive at Nabble.com.
On 01-Nov-08 02:51:37, David Winsemius wrote:> Do you want the count of remaining elements which are strictly > greater than the first element? > > > length(which(a[1] < a[2:10])) > [1] 4 > > or perhaps a bit more deviously: > > > sum( a[1]<a[2:10]+0 ) #adding 0 to TRUE or FALSE creates 1 or 0. > [1] 4No need to be devious! Simply sum(a[1] < a[2:10]) # [1] 4 will do it. The reason is that when TRUE or FALSE are involved in an arithmetic operation (which sum() is), they are cast into 1 or 0. Ted.> On Oct 31, 2008, at 7:56 PM, sandsky wrote: >> Hi there, >> I have a data set: >> >> a=cbind(5,2,4,7,8,3,4,11,1,20) >> >> I want to count # of data, satistfying a[1]<a[2:10]. >> Anyone helps me solving this case? >> >> Thank you in advance, >> Jin-------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 01-Nov-08 Time: 07:30:17 ------------------------------ XFMail ------------------------------