[R] returning quartiles of a list?

Greg Trafton trafton at itd.nrl.navy.mil
Tue Jul 10 17:48:49 CEST 2001

>>>>> Thomas Lumley writes:

> 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

Yep, that did it.  I can now do this kind of thing:

firsthalf <- function(v) {
  n <- length(v)
  return (v[1:(n/2)])

secondhalf <- function(v) {
  n <- length(v)
  return (v[((n%/%2)+1):n])

I'll need to write other functions for 1/3, etc., but that's fine.

thanks again!
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

More information about the R-help mailing list