Declare a function that applies 'forcats::fct_collapse' on a character column.
1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | library(tidyverse)
test_data <-
tibble(
Group = sample(c("Apple", "Pear", "Maple", "Evergreen"), size = 15, replace = TRUE),
A = sample(c(NA_integer_, 1:3), size = 15, replace = TRUE),
B = sample(c(NA_integer_, 4:6), size = 15, replace = TRUE),
C = sample(c(NA_real_, seq(from = 6.01, to = 6.09, by = 0.01)), size = 15, replace = TRUE),
D = sample(c(NA, TRUE, FALSE), size = 15, replace = TRUE)
) %>%
dplyr::mutate(E = B)
categorize_fruits_and_trees <-
categorize_ff(Fruit = c("Apple", "Pear"),
Tree = c("Maple", "Evergreen"))
categorize_fruits_and_trees(data = test_data,
col = Group)
test_data2 <-
tibble(
Group2 = sample(c("Apple", "Pear", "Maple", "Evergreen"), size = 15, replace = TRUE),
A = sample(c(NA_integer_, 1:3), size = 15, replace = TRUE),
B = sample(c(NA_integer_, 4:6), size = 15, replace = TRUE),
C = sample(c(NA_real_, seq(from = 6.01, to = 6.09, by = 0.01)), size = 15, replace = TRUE),
D = sample(c(NA, TRUE, FALSE), size = 15, replace = TRUE)
) %>%
dplyr::mutate(E = B)
test_data3 <-
tibble(
Group3 = sample(c("Apple", "Pear", "Maple", "Evergreen"), size = 15, replace = TRUE),
A = sample(c(NA_integer_, 1:3), size = 15, replace = TRUE),
B = sample(c(NA_integer_, 4:6), size = 15, replace = TRUE),
C = sample(c(NA_real_, seq(from = 6.01, to = 6.09, by = 0.01)), size = 15, replace = TRUE),
D = sample(c(NA, TRUE, FALSE), size = 15, replace = TRUE)
) %>%
dplyr::mutate(E = B)
categorize_fruits_and_trees(data = test_data2,
col = Group2)
categorize_fruits_and_trees(data = test_data3,
col = Group3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.