I would use the grep for the job to map column names to some pattern. Here are some examples:
> a = data.frame(T_a_1=c(1,2,3,4,5), + T_a_2=c(2,3,4,5,6), + T_b_1=c(3,4,5,6,7), + T_c_1=c(4,5,6,7,8), + length=c(1,2,3,4,5)) > >
UPDATE:
In the comments below, I understand that you want to sum the matching lines, grouped by a common prefix and separated by a length column. The following code is an inelegant solution to the problem:
> a = data.frame(ES51_223_1=c(1,2,3,4,5), + ES51_312_1=c(2,3,4,5,6), + ES52_223_2=c(3,4,5,6,7), + ES52_312_2=c(4,5,6,7,8), + ES53_223_3=c(1,2,3,4,5), + length=c(1,2,3,4,5)) > >
m is a matrix containing the results for different prefixes in different columns.