# NOT RUN {
# In data.frame
dfs = data.frame(
aa = rep(10, 5),
b_ = rep(20, 5),
b_1 = rep(11, 5),
b_2 = rep(12, 5),
b_3 = rep(13, 5),
b_4 = rep(14, 5),
b_5 = rep(15, 5)
)
# calculate sum of b_* variables
modify(dfs, {
b_total = sum_row(b_1 %to% b_5)
b_total2 = sum_row(vars("b_`1:5`"))
})
# In global environement
aa = rep(10, 5)
b = rep(20, 5)
a1 = rep(1, 5)
a2 = rep(2, 5)
a3 = rep(3, 5)
a4 = rep(4, 5)
a5 = rep(5, 5)
# identical results
a1 %to% a5
vars("a`1:5`")
vars(perl("^a[0-9]$"))
# sum each row
sum_row(a1 %to% a5)
# }
Run the code above in your browser using DataLab