Message-ID: <Pine.A41.4.33.0107100814020.15808-100000@homer18.u.washington.edu>
Date: 2001-07-10T15:15:48Z
From: Thomas Lumley
Subject: returning quartiles of a list?
In-Reply-To: <15179.6884.19155.654014@viz.itd.nrl.navy.mil>
On Tue, 10 Jul 2001, Greg Trafton wrote:
>
> > process[(n/2):n]
> [1] 4 1 4 1
>
> (this double counts the first 4, of course)
>
> > process[((n/2)+1):n]
> [1] 1 4 1
>
> (but this works for even lists)
>
> > process[(n/4):(n/2)]
> [1] 5 7
>
> (works)
>
> > process <- c( 5 , 7 , 4 , 1 , 4 , 1, 8)
>
> (and this is now an odd list)
>
> > process[1:(n/2)]
> [1] 5 7 4
>
> (works fine)
>
> > process[((n/2)+1):n]
> [1] 1 4 1
>
> (but the bit that worked for the even lists above doesn't work here
> (and I don't quite understand why not...)
Ah. Look at the indexing vector
> ((n/2)+1):n
[1] 4.5 5.5 6.5
You actually want n%/%2 or round(n/2) rather than n/2 to ensure that it is
an integer
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._