I have a question that, I hope, will not be a huge obstacle for advanced users of R ...
test.data <- data.frame(case = c(1, 1, 1, 2, 2, 2, 3), year = c(2006, 2007, 2008, 2007, 2006, 2008, 2006), level = c(10, 20, 20, 12, 20, 20, 20))
As you could see, I have several cases for each case that differ by year. The level values differ in each case, and I would like to fix it by setting each level value to the minimum level of this case. In this example, each level value for case = 1 should be 10, and each level value for case = 2 should be 12. For any particular case, I could do the following:
test.data$level[test.data$case==1] <- min(test.data$level[test.data$case==1])
But since I have several hundred things to do, it will take quite a while. So I would like to ask if you have a faster solution.
source share