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)]
dat2[dat2 < median(dat2)]


below_median <- function(x){ x[x < median(x)]}
above_median <- function(x){ x[x > median(x)]}

below_median(dat1)
below_median(dat2)




Am .12.2015, 09:36 Uhr, schrieb Steven Stoline <[email protected]>:

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:      2    4    8*


*upper half:    11   11   12*



*for Data2: I want to get:*

*lower half:     2   4      8    9*

*upper half:   11   11   12   15*


with many thanks
steve



--
Peter Meißner
Workgroup 'Comparative Parliamentary Politics'
Department of Politics and Administration
University of Konstanz
Box 216
78457 Konstanz
Germany

+49 7531 88 5665
http://www.polver.uni-konstanz.de/sieberer/home/
https://github.com/petermeissner
http://pmeissner.com

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

Reply via email to