Вот решение с dplyr
.
library(dplyr)
library(ggplot2)
df2 %>%
group_by(time) %>%
mutate(anzahl = sum(as.numeric(anzahl), na.rm = TRUE)) %>%
ungroup() %>%
group_by(time, anzahl) %>%
summarise(minuten = mean(minuten)) %>%
mutate(ratio = minuten / anzahl) %>%
ungroup() %>%
mutate(time = factor(time, levels = month.abb[1:4], labels = month.abb[1:4])) %>%
ggplot(aes(time, ratio)) + geom_point() + ylab("minuten / anzahl")
Данные
df2 <- structure(list(time = structure(c(3L, 3L, 3L, 3L, 2L, 2L, 4L,
4L, 4L, 1L), .Label = c("Apr", "Feb", "Jan", "Mar"), class = "factor"),
anzahl = c("", "", "", "23", "", "3", "", "", "5", "56"),
minuten = c(0.051252949051559, 0.749002492986619, 0.0514915327075869,
0.20246379589662, 0.16418539150618, 0.785793941700831, 0.841768049867824,
0.255166659131646, 0.0798644754104316, 0.00516700255684555
)), .Names = c("time", "anzahl", "minuten"), row.names = c(NA,
-10L), class = "data.frame")