Re: [R-sig-teaching] subsetting data with the median position

2015-12-22 Thread Peter Meissner
hmmm, maybe those were a little shortsighted and fasttyped... > > dat1 <- c(2,4,8,9,11,11,11,12,15) > > dat1[dat1 > median(dat1)] > [1] 12 15 > dat1[dat1 < median(dat1)] > [1] 2 4 8 9 > .. but that should reliably split: median_split <- function(x){ n <- floor(length(x) / 2) x <-

Re: [R-sig-teaching] subsetting data with the median position

2015-12-22 Thread Steven Stoline
Thank you very much for your helps steve On Tue, Dec 22, 2015 at 3:53 AM, Peter Meissner < peter.meiss...@uni-konstanz.de> wrote: > dat1 <- c(2,4,8,9,11,11,12) > > dat1[dat1 > median(dat1)] > dat1[dat1 < median(dat1)] > > > > dat2 <- c(2,4,8,9,11,11,12,15) > > dat2[dat2 > median(dat2)] >

[R-sig-teaching] subsetting data with the median position

2015-12-22 Thread Steven Stoline
Dear All: is there away for subsetting data by the median position? Example: *Data1: *2, 4, 8, 9,11,11,12 *(n is odd)* *Data1: *2,4,8,9,11,11,12,15 * (n is even)* for Data1: * I want to get:* *lower half: 248* *upper half:11 11 12* *for Data2: I

Re: [R-sig-teaching] subsetting data with the median position

2015-12-22 Thread Albyn Jones
> dat1 <- c(2,4,8,9,11,11,11,12,15) > > dat1[dat1 > median(dat1)] [1] 12 15 > dat1[dat1 < median(dat1)] [1] 2 4 8 9 I'm just curious: do you like this too? albyn On Tue, Dec 22, 2015 at 1:00 AM, Steven Stoline wrote: > Thank you very much for your helps > > steve > > On

Re: [R-sig-teaching] subsetting data with the median position

2015-12-22 Thread Randall Pruim
The issue of ties probably has no answer that is best in all situations. Here’s what mosaic::ntiles() does: > x <- c(2,4,8,9,11,11,11,12,15) > rbind(x, ntiles(x, 2)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] x2489 11 11 11 12 15 111112