0

The summarise function in dplyr by means the group by function returns a single value, even though the group by is filled with a factor. What is wrong here?

cols <- c("GGEES203","cl_kmeans")
y <- y[which(y$cl_kmeans>0),cols]
y$cl_kmeans <- as.factor(y$cl_kmeans)
str(y)
    'data.frame':   3863 obs. of  2 variables:
     $ GGEES203 : num  4 11 3 0 9 0 10 11 8 10 ...
     $ cl_kmeans: Factor w/ 9 levels "1","2","3","4",..: 6 4 3 3 6 6 4 9 9 5 ...
gd <- y %>% 
group_by(cl_kmeans) %>% 
summarise(eenzaamheid_avg = mean(GGEES203, na.rm = TRUE))


      eenzaamheid_avg
    1            7.29
    > 
Mark Henry
  • 2,649
  • 7
  • 40
  • 48

0 Answers0