# Attach packages
library(rearrr)
# Add 90 to all degrees
# Note that 0 and 360 is considered the same angle
# why there is no distance between the two
roll_values(c(0:360), add = 90)
# Get as vector
roll_values_vec(c(0:360), add = 90)
# Change limits to 0-180
# so e.g. 270 becomes 90
roll_values(c(0:360), .min = 0, .max = 180)
# Change values first, then wrap to range
x <- c(1:7)
x <- x^2
wrap_to_range(x, .min = 1, .max = 7)
# With 1 in-between .min and .max
wrap_to_range(x, .min = 1, .max = 7, between = 1)
# Get as vector
wrap_to_range_vec(x, .min = 1, .max = 7, between = 1)
#
# Roll data.frame
#
# Set seed
set.seed(1)
# Create a data frame
df <- data.frame(
"w" = 1:7,
"d" = c(0, 45, 90, 135, 180, 270, 360)
)
# Roll weekdays by 1 day
roll_values(
df,
cols = "w",
add = 1,
.min = 1,
.max = 7,
between = 1
)
# Roll degrees by -90 degrees
roll_values(
df,
cols = "d",
add = -90,
.min = 0,
.max = 360,
between = 0
)
# Roll both weekdays and degrees by 1
# We don't specify .min and .max, so they
# are based on the values in the columns
# Note: This is not that meaningful but shows
# the option
roll_values(
df,
cols = c("w", "d"),
add = 1
)
# Wrap weekdays to 2-5 range
wrap_to_range(
df,
cols = "w",
.min = 2,
.max = 5,
between = 1
)
Run the code above in your browser using DataLab