A simple tidyverse solution would rely on dplyr's mutate function, for example below
library(dplyr)
df <- tibble(
a = 1:4,
b = 4:7
)
df <- df %>%
mutate(
c = (a + b) / 2
)
df
#> # A tibble: 4 x 3
#> a b c
#> <int> <int> <dbl>
#> 1 1 4 2.5
#> 2 2 5 3.5
#> 3 3 6 4.5
#> 4 4 7 5.5
Created on 2019-02-20 by the reprex package (v0.2.1)
Created on 2019-02-20 by the reprex package (v0.2.1)
I'd encourage you to take a good intro to R and/or the tidyverse to get familiar with data manipulation topics like this. You can good vignettes or check out the cheatsheets.
Garret also made a nice webinar on data wrangling here.