Last chance! 50% off unlimited learning
Sale ends in
These functions are intended for usage inside compute, and
do_if. sum/mean/sd/median/max/min by default omits NA. any_in_*
checks existence of any TRUE in each row/column. It is equivalent of
any applied to each row/column. all_in_*
is equivalent of
all applied to each row/column.
sum_row(..., na.rm = TRUE)sum_col(..., na.rm = TRUE)
mean_row(..., na.rm = TRUE)
mean_col(..., na.rm = TRUE)
sd_row(..., na.rm = TRUE)
sd_col(..., na.rm = TRUE)
median_row(..., na.rm = TRUE)
median_col(..., na.rm = TRUE)
max_row(..., na.rm = TRUE)
max_col(..., na.rm = TRUE)
min_row(..., na.rm = TRUE)
min_col(..., na.rm = TRUE)
apply_row(fun, ...)
apply_col(fun, ...)
any_in_row(..., na.rm = TRUE)
any_in_col(..., na.rm = TRUE)
all_in_row(..., na.rm = TRUE)
all_in_col(..., na.rm = TRUE)
data. Vectors, matrixes, data.frames, list. Shorter arguments will be recycled.
logical. Contrary to the base 'sum' it is TRUE by default. Should missing values (including NaN) be removed?
custom function that will be applied to …
All functions except apply_*
return numeric vector of length
equals the number of argument columns/rows. Value of apply_*
depends
on supplied fun
function.
compute, do_if, %to%, count_if, sum_if, mean_if, median_if, sd_if, min_if, max_if
# NOT RUN {
iris = compute(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
compute(dfs, {
b_total = sum_row(b_, b_1 %to% b_5)
})
# conditional modification
do_if(dfs, test %in% 2:4, {
b_total = sum_row(b_, b_1 %to% b_5)
})
# }
Run the code above in your browser using DataLab