# Attach packages
library(rearrr)
library(dplyr)
# Set seed
set.seed(1)
# Create three vectors
x <- runif(10)
y <- runif(10)
z <- runif(10)
# Find midrange for each vector
midrange(x, y, z)
#
# For data.frames
#
# Create data frame
df <- data.frame(
"x" = x,
"y" = y,
"z" = z,
"g" = rep(1:2, each = 5)
)
# Find midrange for each column
midrange(df, cols = c("x", "y", "z"))
# When 'df' is grouped
df %>%
dplyr::group_by(g) %>%
midrange(cols = c("x", "y", "z"))
Run the code above in your browser using DataLab