## Inside example
iris = modify(iris,{
new_median = median_row(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
new_mean = mean_row(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
})
dfs = data.frame(
test = 1:5,
aa = rep(10, 5),
b_ = rep(20, 5),
b_1 = rep(11, 5),
b_2 = rep(12, 5),
b_4 = rep(14, 5),
b_5 = rep(15, 5)
)
# calculate sum of b* variables
modify(dfs, {
b_total = sum_row(b_, b_1 %to% b_5)
})
# conditional modification
modify_if(dfs, test %in% 2:4, {
b_total = sum_row(b_, b_1 %to% b_5)
})
# Examples from rowSums/colSums manual.
## Compute row and column sums for a matrix:
x = cbind(x1 = 3, x2 = c(4:1, 2:5))
sum_row(x); sum_col(x)
dimnames(x)[[1]] <- letters[1:8]
sum_row(x); sum_col(x); mean_row(x); mean_col(x)
Run the code above in your browser using DataLab