I got a problems that bugs me for some time… hopefully anybody here can help me.
I got the following data frame
f <- c('a','a','b','b','b','c','d','d','d','d')
v1 <- c(1.3,10,2,10,10,1.1,10,3.1,10,10)
v2 <- c(1:10)
df <- data.frame(f,v1,v2)
f is a factor; v1 and v2 are values.
For each level of f, I want only want to keep one row: the one that has the lowest value of v1 in this factor level.
f v1 v2
a 1.3 1
b 2 3
c 1.1 6
d 3.1 8
I tried various things with aggregate, ddply, by, tapply… but nothing seems to work. For any suggestions, I would be very thankful.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…