我有一个包含三个变量的数据,我希望将id行保持为高“value”,并删除每个id的“value”值较低的行。
我有什么
mydata <- data.frame(id=c(1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,4), case=c("a","b","c","c","b","a","b","c","c","a","b","c","c","a","b","c","a","b"), value=c(1,1,1,2,2,1,1,2,2,2,2,1,1,1,1,1,2,2))
我需要什么
id case value
4 1 c 2
5 1 b 2
8 2 c 2
9 2 c 2
10 3 a 2
11 3 b 2
17 4 a 2
18 4 b 2
谢谢!
答案 0 :(得分:2)
尝试:
mydata[mydata$value==ave(mydata$value,mydata$id,FUN=max),]
答案 1 :(得分:0)
mydata[mydata$value>1,]
或
mydata[mydata$value>min(mydata$value),]