# [R] returning quartiles of a list?

Thomas Lumley tlumley at u.washington.edu
Tue Jul 10 17:15:48 CEST 2001

```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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```