I have two data frames. df1 and df2. both with c columns
using a clustering method, I ended up with 10 clusters. same clusters for each df is true. this means for example the 4th row of both df s go to the same cluster.
I added a cluster column to both dfs, showing the assigned cluster for each row.
I want to create a list.
this list contains 10 matrices, such that.
matrix 1, is a 2*c matrix. its first row is obtained by colmeans of those rows of df1 which are in cluster 1. and its 2nd row is obtained by colmeans of those rows of df2 which are in cluster 1.
and matrix 2 , colmeans of cluster 2 and so on.
this is what I ve done. but I get the 10th matrix only and not a list of matrices 1 to 10.
I would appreciate any help with this.
k=10
for(i in 1:k){
df1.mean.vec <- colMeans(subset(df1, clster == i))
df2.mean.vec <- colMeans(subset(df2, clster == i))
Mean.mat <- as.matrix(rbind(df1.mean.vec, df2.mean.vec), row.names= FALSE)
Mean.list <- list()
Mean.list[[i]] <- Mean.mat
names(Mean.list)[i] <- i
}