Hi everybody!
I have a data frame like this:
db_class <- data.frame(A=c(2,3,9,12,2,5,7,7,1,23,3,4,14,3,9,8,6,11,9,4),B=c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2)
db_class
vals <- by(db_class$A, db_class$B, FUN = function(x) {
pos = which.max(x)
pos_plus_minus = c(pos-3, pos-2, pos-1,
pos,
pos+1, pos+2, pos+3)
x[pos_plus_minus]
})
db_finale <-do.call(rbind, vals)
db_finale <- as.data.frame(db_finale)
final<- db_finale[db_finale$V4<20,]
final
This code is slow and I need something to fast. I would like to know if it would be possible to move the code "final" in the part of the program where the translation of the dataset happens "vals".
Thank you!