I\'ve got a dataframe that\'s got lots of columns that are something like this:
data <- data.frame (a.1 = 1:5, a.2b = 3:7, a.5 = 5:9, bt.16 = 4:8, bt.1234
Here's another tidyverse solution:
tidyverse
library(tidyverse) t(data) %>% data.frame() %>% group_by(., id = gsub('\\..*', '', rownames(.))) %>% summarise_all(sum) %>% data.frame() %>% column_to_rownames(var = 'id') %>% t()
Result:
a bt X1 9 11 X2 12 13 X3 15 15 X4 18 17 X5 21 19