aggregate a matrix (or data.frame) by column name groups in R
问题 I have a large matrix with about 3000 columns x 3000 rows. I'd like to aggregate (calculate the mean) grouped by column names for every row. Each column is named similar to this method...(and in random order) Tree Tree House House Tree Car Car House I would need the data result (aggregation of mean of every row) to have the following columns: Tree House Car the tricky part (at least for me) is that I do not know all the column names and they are all in random order! 回答1: You could try res1 <-