[R] sum column by colnames

Alfredo Alessandrini alfreale74 at gmail.com
Wed Jan 20 13:59:03 CET 2010


Hi,

I've this dataframes:

> data1
             1        2 3         4             5                6
5    0.4963017 0 0 0.2481509  1.9852069 0.4963017
10   0.0000000 0 0 0.0000000  0.6317266 0.0000000
15   0.0000000 0 0 0.0000000  0.0000000 0.0000000
20   0.0000000 0 0 3.3955301  0.0000000 0.0000000
25   0.0000000 0 0 0.0000000  0.0000000 0.0000000
30   0.0000000 0 0 0.0000000  0.0000000 0.0000000
35   0.0000000 0 0 0.0000000  0.0000000 0.0000000

> data2
           1        4              5                6
5    0.00000  0.00000  0.00000  0.0000000
10   0.00000  0.00000  0.00000  0.5849502
15   0.00000  0.00000  0.00000  0.0000000
20   0.00000  0.00000  0.00000  0.0000000
25   0.00000 10.49815  0.00000  0.0000000

Can I sum the dataframe, by colnames?

The sum is:

             1        2 3         4             5                6
5    0.4963017 0 0 0.2481509  1.9852069 0.4963017
10   0.0000000 0 0 0.0000000  0.6317266 0.5849502
15   0.0000000 0 0 0.0000000  0.0000000 0.0000000
20   0.0000000 0 0 3.3955301  0.0000000 0.0000000
25   0.0000000 0 0 10.498150   0.0000000 0.0000000
30   0.0000000 0 0 0.0000000  0.0000000 0.0000000
35   0.0000000 0 0 0.0000000  0.0000000 0.0000000


Thanks,

Alfredo



More information about the R-help mailing list