I want to make a mean matrix, whose first row is mean value of columns of df1 who have value i on their clster column, and whose 2nd row is mean value of columns of df2 who have value i on their clster column. I ran code below:
for (i in 1:k) {
df.1[[i]] <- assign(paste0("df1.clstr",i), df1[df1$clster==i,])
df.2[[i]] <- assign(paste0("df2.clstr",i), df2[df2$clster==i,])
Mean.list[[i]]<- matrix(colSums(df.1[[i]])/nrow(df.1[[i]]),colSums(df.2[[i]])/nrow(df.2[[i]])),nrow = 2, ncol = 5, byrow = TRUE)
}
I get error :
Error in colSums(dth[dth$clster == i, ]) : 'x' must be numeric
when I use as.numeric, I get:
Error in is.data.frame(x) : 'list' object cannot be coerced to type 'double'
What is my mistake here?