I have a data table "the.data" where the first column indicates the measuring tool and the rest are different measured data.
instrument <- c(1,2,3,4,5,1,2,3,4,5)
hour <- c(1,1,1,1,1,2,2,2,2,2)
da <- c(12,14,11,14,10,19,15,16,13,11)
db <- c(21,23,22,29,28,26,24,27,26,22)
the.data <- data.frame(instrument,hour,da,db)
I also defined tool groups, where, for example, group 1 (g1) refers to tools 1 and 2.
g1 <- c(1,2)
g2 <- c(4,3,1)
g3 <- c(1,5,2)
g4 <- c(2,4)
g5 <- c(5,3,1,2,6)
groups <- c("g1","g2","g3","g4","g5")
I need to find out what time the sum of each group has a maximum for each data type and its amount.
g1 hour 1: amount (da) = 12 + 14 = 26 g1 hour 2: amount (da) = 19 + 15 = 34
So, for g1 and da the answer is hour 2 and value 34.
I did this with a for loop inside the loop, but it takes too much time (I interrupted after a few hours). The problem is that the.data is about 100,000 lines and that there are about 5,000 groups with 2-50 tools each.
What could be a good method to do this?
Stack-overflow.
: .
/Chris