I need to get col sum for all the columns and have the result in a data frame with colnames and their sum as two columns. But if I do this, column name seem to become index rather than a col itself.
demo=data.frame(a=runif(10),b=runif(10,max=2),c=runif(10,max=3))
as.data.frame(colSums(demo))
The undesired result:
colSums(demo)
a 4.083571
b 11.698794
c 14.082574
The desired result:
colname colSums(demo)
a 4.083571
b 11.698794
c 14.082574
How can I add a heading to the column on the left while keep the shape as it is? Thanks.