returning quartiles of a list?
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!
greg
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._