Set column name ddply
问题 How to set the column name of the summarized data in library(plyr) ddply(data,.(col1,col2),nrow) like in ddply(data,.(col1,col2),function(x) data.frame(number=nrow(x))) 回答1: Perhaps you are looking for summarize (or mutate or transform , depending on what you want to do). A small example: set.seed(1) data <- data.frame(col1 = c(1, 2, 2, 3, 3, 4), col2 = c(1, 2, 2, 1, 2, 1), z = rnorm(6)) ddply(data,.(col1,col2), summarize, number = length(z), newcol = mean(z)) # col1 col2 number newcol # 1 1