# Attach packages
library(rearrr)
library(dplyr)
# Set seed
set.seed(1)
# Create a data frame
df <- data.frame(
"x" = runif(20),
"y" = runif(20),
"g" = rep(1:4, each = 5)
)
# Measure row-wise
vector_length(df, cols = c("x", "y"), by_row = TRUE)
# Measure column-wise
vector_length(df, cols = c("x", "y"), by_row = FALSE)
# By groups in 'g'
df %>%
dplyr::group_by(g) %>%
vector_length(cols = c("x", "y"), by_row = FALSE)
# Measure vector length of a vector
vector_length(c(1:10))
Run the code above in your browser using DataLab