1 2 3 4 5 6 7 8 9 10 11
| # Jeu de data bidon
test <- data.frame(a=rnorm(81), b=c(15:59,500:512,1323:1345))
# test <- data.frame(a=rnorm(240), b=c(0:59,100:159,500:559,1300:1359))
# Formatage de b en date
test$b <- strptime(sprintf("%04d", test$b), format="%H%M")
# Calcul de la difference avec la date "minimum" en minutes
test$b.diff <- as.numeric(difftime(test$b, min(test$b), units="min"))
# Creation d'une variable qui groupe les donnees par tranches de 15 minutes
test$b.cut <- test$b.diff %/% 15
# Calcul de la moyenne par groupe
with(test, tapply(a, b.cut, mean)) |
Partager