How can I get each numeric column's mean in one data?

后端 未结 2 1421
盖世英雄少女心
盖世英雄少女心 2021-01-28 10:16

I have data named cluster_1. It has nominal variable from first column to the third.

# select the columns based on the clustering results
cluster_1 <- mat[whi         


        
相关标签:
2条回答
  • 2021-01-28 10:37

    colMeans() will give you the mean of each column in a data frame or matrix. And rbind() can be used to append the result.

    rbind(cluster_1[, -(1:3)], colMeans(cluster_1[, -(1:3)]))
    
    0 讨论(0)
  • 2021-01-28 10:44

    A generalization of what you are doing can be found with the function addmargins. Try, for example:

    cluster_1Means <- addmargins(cluster_1[, -(1:3)], margin = 1, FUN = mean)
    cluster_1Means
    
    0 讨论(0)
提交回复
热议问题