与dplyr汇总,按功能忽略因子

时间:2018-11-14 13:56:30

标签: r dplyr

dplyr中的summary函数by表示group by函数返回单个值,即使group by用一个因子填充。怎么了?

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
    > 

0 个答案:

没有答案