-3

This is my data

> df<- as.data.frame(matrix(rnorm(15), 3))

> df

          V1         V2         V3          V4         V5
1  0.8757347  1.5984067  1.0295143  0.08161545  1.6208651
2 -0.4039117 -0.9497641 -0.1747716  0.01544082  0.4639266
3 -0.9055205 -0.9686378  0.9451551 -0.05030505 -1.4510613

How can I add a column at the end that will sum only the last two column?

Mac
  • 111
  • 1
  • 2
  • 10

1 Answers1

2

This should do it

df<- as.data.frame(matrix(rnorm(15), 3))
> df$V6 <- df$V4 + df$V5
> df
          V1        V2          V3        V4         V5         V6
1 -1.9786737 0.3909885 -0.03734145 0.1851501  1.5787765  1.7639266
2 -0.4523491 0.6529999 -2.21683918 1.4337437  0.1738136  1.6075573
3  0.4503717 0.3944558  0.84851336 0.3843997 -0.9938039 -0.6094042
> 
Dinesh.hmn
  • 713
  • 7
  • 21