Summing multiple columns across a single row, for multiple rows

I’m not sure if this is part of a larger data frame and how you intend to apply this there, but I might use the map function in purrr.

library(purrr)
df <- data.frame(X0.61=c(1, 2, 3, 4, 5),
             X0.225=c(3, 4, 5, 6, 7),
             X0.329=c(4, 5, 6, 7, 8),
             X0.553=c(5, 6, 7, 8, 9))
map(df[c(1,3), c(1,2,4)], sum)


$X0.61
4
$X0.225
8
$X0.553
12

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top