0

I have data frame like this.

head(bus_pop)[-c(1:2)]
   a1 a2 a3 a4 a5 a6 a7 a8  a9 a10 a11 a12 a13
1   1  0  0  0  0  0  0  0  77 127 160 238  76
2   0  0  0  0  0  0  0  0 113 180 163 300  60
3   0  2  0  0  0  0  0  0 106  89 100 310  48
4   0  0  0  0  0  0  0  0  41  97  66 285  41
5  19 34  1  0  1  0  0  0   0   0   0   0   9
6 157 21  2  0  1  0  0  0   0   0   0   0  10

And I want to create new column "total". So I write code like this.

bus_pop %>% 
  mutate(total = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13)

How can I make to short cording?

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
Eonsworld
  • 3
  • 2

0 Answers0