R - creating dataframe from colMeans function -


i've been trying create dataframe original dataframe, rows in new dataframe represent mean of every 20 rows of old dataframe. discovered function called colmeans, job pretty well, problem, still persists how change vector of results dataframe, can further analysed.

my code colmeans: (matrix1 in original dataframe converted matrix, way managed work)

a<-colmeans(matrix(matrix1, nrow=20)); 

but here numeric sequence, has results concatenated in 1 single column(if try example as.data.frame(a)). how supposed result dataframe each column includes results specific column name , not averages.

i hope question clear, help.

based on methods('as.data.frame'), as.data.frame.list option convert each element of vector columns of data.frame

as.data.frame.list(a) 

data

m1 <- matrix(1:20, ncol=4, dimnames=list(null, paste0('v', 1:4))) <- colmeans(m1) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -