[R] row selection based on median in data frame
Ed L Cashin
ecashin at uga.edu
Thu Apr 1 05:22:22 CEST 2004
Hi. I am having trouble thinking of an easy way to grab rows out of a
data frame. I want to select the rows with a median value when the
rows are similar.
A simple example is this table, which I could read into a data frame.
I would like to find a new data frame with only the rows with a median
value for the "c" column given a certain "a" value.
For example, the c values for deadlift rows are 13, 8, and 5, so the
row with a c value of 8 should show up in the output.
a b c
1 deadlift 7 13
2 squat 7 24
3 clean 7 10
4 deadlift 8 8
5 squat 8 20
6 clean 8 2
7 deadlift 9 5
8 squat 9 32
9 clean 9 19
Result:
a b c
4 deadlift 8 8
5 squat 8 20
3 clean 7 10
It's more complicated in my case, because I have not just one "a"
column, but about eight columns that have to be the same. I can do
this with clumsy loops, but I wonder whether there's a better way.
--
--Ed L Cashin | PGP public key:
ecashin at uga.edu | http://noserose.net/e/pgp/
More information about the R-help
mailing list