dataframe - Use first part of value as header in r -


i have data frame generated t(summary(raw_data())):

original data frame

however, each cell has prefix of max, min, mean, etc... , remove prefix each row , put @ header. there easy way in r dataframe this:

desired data frame

also, far variables 3 & 18 factors. i'm less concerned about.

we can loop through columns of dataset, summary , rbind output

do.call(rbind, lapply(raw_data, summary)) 

using reproducible example

do.call(rbind, lapply(iris[1:4], summary)) #              min. 1st qu. median  mean 3rd qu. max. #sepal.length  4.3     5.1   5.80 5.843     6.4  7.9 #sepal.width   2.0     2.8   3.00 3.057     3.3  4.4 #petal.length  1.0     1.6   4.35 3.758     5.1  6.9 #petal.width   0.1     0.3   1.30 1.199     1.8  2.5 

Comments