ron-r
1/26/2014 - 10:06 AM

building an average variable value per cluster in a table

building an average variable value per cluster in a table

data<-read.csv(choose.files(),header = TRUE, sep = ",")
fit <- kmeans(data, 15) # 5 cluster solution
# get cluster means 
aggregate(data,by=list(fit$cluster),FUN=mean)
# append cluster assignment
mydata <- data.frame(data, fit$cluster)

#Other methods for appending clusters
aggregate(cbind(AverageDepoAmount,PromotionDeposits,DepoCount)~ClusterNumber,NewResSep13,FUN=mean)


OR (IN ORDER TO ADD THE COUNTS PER CLUSTER): 
a<-aggregate(cbind(ClusterNumber)~ClusterNumber,NewResSep13,FUN=length)
> b<-aggregate(cbind(AverageDepoAmount,PromotionDeposits,DepoCount)~ClusterNumber,NewResSep13,FUN=mean)
> c<-cbind(a,b)


Another option by using library (doBy)
> library(doBy)
> summaryBy(snakes ~ Country , data = dat, FUN = mean)