I have data which looks like this (this is test data for illustration):
test <- matrix(c(1, 1, 1, 2, 2, 2 , 529, 528, 528, 495, 525, 510,557, 535, 313,502,474, 487 ), nr=6, dimnames=list(c(1,2,3,4,5,6),c("subject", "rt1", "rt2")))
And I need to turn it into this:
test2<-matrix(c(1,1,1,2,2,2,529,528,528,495,525,510,"slow","slow","fast","fast","slow","slow",557, 535, 313,502,474, 487,"fast","fast","slow","slow","fast","fast"), nr=6, dimnames=list(c(1,2,3,4,5,6),c("subject", "rt1","speed1", "rt2","speed2")))
The speed1 column is calculated thus: calculate the median rt1 for the subject. If the individual value is less than the median it scores fast. If the individual cell value of rt1 is more than the median it scores slow. If the cell value is at the median, the cell is removed from the analysis (delete or NA) and the median for that subject is recalculated. This process is repeated for the speed2 column, but using rt2.
Perhaps some kind of if statement?
To clarify: I want the median for each subject (there are 40 in total) and for any values that are at the median (for that subject) to be excluded and the median recalculated (for that subject).