| rev_windows | R Documentation |
The values are windowed and reversed within windows.
The *_vec() version takes and returns a vector.
Example:
The column values:
c(1, 2, 3, 4, 5, 6)
With window_size = 3
Are ordered as:
c(3, 2, 1, 6, 4, 5)
rev_windows(data, window_size, factor_name = ".window", overwrite = FALSE)
rev_windows_vec(data, window_size)
data |
|
window_size |
Size of the windows. (Logical) |
factor_name |
Name of the factor with window identifiers.
If |
overwrite |
Whether to allow overwriting of existing columns. (Logical) |
The sorted data.frame (tibble) / vector.
Optionally with the windows factor added.
When `data` is a vector and `keep_windows` is FALSE,
the output will be a vector. Otherwise, a data.frame.
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Other rearrange functions:
center_max(),
center_min(),
closest_to(),
furthest_from(),
pair_extremes(),
position_max(),
position_min(),
roll_elements(),
shuffle_hierarchy(),
triplet_extremes()
# Attach packages
library(rearrr)
library(dplyr)
# Set seed
set.seed(1)
# Create a data frame
df <- data.frame(
"index" = 1:10,
"A" = sample(1:10),
"B" = runif(10),
"C" = LETTERS[1:10],
"G" = rep(1:2, each = 5),
stringsAsFactors = FALSE
)
# For vector
rev_windows_vec(1:10, window_size = 3)
# For data frame
rev_windows(df, window_size = 3)
rev_windows(df, window_size = 3, factor_name = NULL)
# Grouped by G
df %>%
dplyr::select(G, index) %>% # For clarity
dplyr::group_by(G) %>%
rev_windows(window_size = 3)
# Plot the extreme pairs
plot(
x = 1:10,
y = rev_windows_vec(1:10, window_size = 3)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.