I have a data frame where several columns may have the same name. In this small example, both column \"A\" and \"G\" occur twice:
A C G A G T 1 1
We can transpose dat , calculate rowsum per group (colnames of the original dat), then transpose the result back to original structure.
dat
rowsum
colnames
t(rowsum(t(dat), group = colnames(dat), na.rm = T)) # A C G T #1 1 0 1 0 #2 4 0 6 0 #3 0 1 0 1 #4 2 0 1 0 #5 1 0 1 0 #6 0 1 0 1 #7 0 1 0 1