To create or modify variables, you can use the mutate() function from dplyr package, see this example.
# Sample Data
df <- data.frame(
Id = c(1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2),
Year = c(1951, 1956, 1957, 1958, 1959, 1960, 1961, 1951, 1956, 1957,
1958, 1959, 1960, 1961),
X1 = c(45939, 60423, 64721, 68484, 71799, 76036, 79831, 45939, 60423,
64721, 68484, 71799, 76036, 79831),
X2 = c(21574, 29990, 32510, 35218, 37598, 40341, 43173, 21574, 29990,
32510, 35218, 37598, 40341, 43173),
X3 = c(2876, 4708, 5230, 6662, 6856, 8220, 9053, 2876, 4708, 5230,
6662, 6856, 8220, 9053)
)
library(dplyr)
df %>%
mutate(X2 = X2 * 2,
X3 = 0,
new_X = X1 + X2)
#> Id Year X1 X2 X3 new_X
#> 1 1 1951 45939 43148 0 89087
#> 2 1 1956 60423 59980 0 120403
#> 3 1 1957 64721 65020 0 129741
#> 4 1 1958 68484 70436 0 138920
#> 5 1 1959 71799 75196 0 146995
#> 6 1 1960 76036 80682 0 156718
#> 7 1 1961 79831 86346 0 166177
#> 8 2 1951 45939 43148 0 89087
#> 9 2 1956 60423 59980 0 120403
#> 10 2 1957 64721 65020 0 129741
#> 11 2 1958 68484 70436 0 138920
#> 12 2 1959 71799 75196 0 146995
#> 13 2 1960 76036 80682 0 156718
#> 14 2 1961 79831 86346 0 166177
Created on 2019-07-27 by the reprex package (v0.3.0.9000)