我有看起来像这样的数据(这是用于说明的测试数据):
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")))
我需要把它变成这样:
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")))
speed1 列是这样计算的:计算对象的中值 rt1。如果单个值小于中位数,则得分很快。如果 rt1 的单个单元格值大于中位数,则得分缓慢。如果单元格值为中位数,则从分析中删除该单元格(删除或 NA)并重新计算该受试者的中位数。对 speed2 列重复此过程,但使用 rt2。
也许某种 if 语句?
澄清一下:我希望排除每个主题的中位数(总共 40 个)以及任何处于中位数(对于该主题)的值,并重新计算中位数(对于该主题)。