library(dplyr) ##activates the data.table library
mydataWithWeeksAndWeights <- data_frame(ended = c("14/11/2016",
"14/11/2016",
"14/11/2016",
"02/01/2017",
"02/01/2017",
"15/11/2017",
"15/11/2017",
"16/11/2017",
"16/11/2017"),
week = c(46, 46, 46, 1, 1, 46, 46, 46, 46),
satisfactionLevel = c("Very dissatisfied",
"Very satisfied",
"Satisfied",
"Dissatisfied",
"Very dissatisfied",
"Very satisfied",
"Very dissatisfied",
"Very Satisfied",
"Very satisfied"),
weight = c(0, 1, 0.75, 0.25, 0, 1, 0, 1, 1))
Wenn ich die Funktion folgende nennen pivotTable <- mydataWithWeeksAndWeights %>% group_by(week, weight) %>% count(satisfactionLevel)
den satisfactionLevel 46 Einträge für alle Woche zählt. Das Problem ist, dass sich die 46. Woche für die ersten drei Zeilen auf 2016 bezieht und die restlichen 2017 beziehen. Ich möchte diese doppelten Einträge behalten.Halten Sie doppelte Einträge, wo ich group_by() verwenden, von dplyr
Versuchen Sie 'mydataWithWeeksAndWeights%>% group_by (Woche, Gewicht)%>% Filter (n()> 1)' – akrun
Ich denke, Sie möchten zwischen den Jahren unterscheiden. Sie können dies mit 'df%>% group_by (Jahr_Woche = Format (als Datum (beendet,"% d /% m /% Y "),"% Y-% W "), Gewicht)%>% Anzahl (satisfactionLevel) ' –
@docendodiscimus Legendär !!! Prost – Greconomist