How to collapse rows in a dataframe?

Ok, so you've more than two rows? Then, I think it does what you're trying to do.

df <- data.frame(a = 1:5,
                 b = 11:15,
                 c = 21:25)

df
#>   a  b  c
#> 1 1 11 21
#> 2 2 12 22
#> 3 3 13 23
#> 4 4 14 24
#> 5 5 15 25

df[1,] <- (df[1,] + df[2,])

df <- df[-2,]

df
#>   a  b  c
#> 1 3 23 43
#> 3 3 13 23
#> 4 4 14 24
#> 5 5 15 25

Created on 2019-03-20 by the reprex package (v0.2.1)

But most probably not what you're looking for. It's anything but smart.

You can check this SO post:

For your future posts, please ask with a reproducible example.

1 Like