I want to calculate each column's sample deviation in data

↘锁芯ラ 提交于 2020-01-06 12:39:04

问题


I am doing cluster analysis based on data "college" which consists of 3 nominal and 20 numeric variables.

# select the columns based on the clustering results
cluster_1 <- mat[which(groups==1),]

#"cluster_1" is a data set which is made by cluster analysis consisting of 125 observations.


rbind(cluster_1[, -(1:3)], colMeans(cluster_1[, -(1:3)]))
#This is process of calculating each column's mean and attach the means to the bottom of the data set, "cluster_1".

Now what I want to know is how to calculate each column's sample variance and sample deviation and how to attach them to the bottom of the data set "cluster_1".

Please let me know.


回答1:


  rbind(cluster_1, apply(cluster_1,2,sd), apply(cluster_1, 2, var) )


来源:https://stackoverflow.com/questions/20276711/i-want-to-calculate-each-columns-sample-deviation-in-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!