I would like to add a row to the data frame displaying the totals of the column.
test = data.frame('name' = c('a','b','c'),'x' = c(1,2,3),'y' = c(1,2,3))
class(test[,2])
[1] "numeric"
test = rbind(test,c('Total',apply(test[,-1],2,sum)))
name x y
1 a 1 1
2 b 2 2
3 c 3 3
4 Total 6 6
class(test[,2])
[1] "character"
I need the numeric columns to remain numeric. I understand that this is because the mixed vector that I am trying to add is actually a symbolic character. What good is this? I tried rbind with a list, but it did not work with the apply function.
Thanks in advance
source
share