cut_by_group | R Documentation |
Cutting data by group
cut_by_group(df, col_data, col_group, group, cat_col)
df |
( |
col_data |
( |
col_group |
( |
group |
( |
cat_col |
( |
Function used to categorize numeric data stored in long format depending on their group. Intervals are closed on the right (and open on the left).
data.frame
with a column containing categorical values.
group <- list(
list(
"Height",
c(-Inf, 150, 170, Inf),
c("=<150", "150-170", ">170")
),
list(
"Weight",
c(-Inf, 65, Inf),
c("=<65", ">65")
),
list(
"Age",
c(-Inf, 31, Inf),
c("=<31", ">31")
),
list(
"PreCondition",
c(-Inf, 1, Inf),
c("=<1", "<1")
)
)
data <- data.frame(
SUBJECT = rep(letters[1:10], 4),
PARAM = rep(c("Height", "Weight", "Age", "other"), each = 10),
AVAL = c(rnorm(10, 165, 15), rnorm(10, 65, 5), runif(10, 18, 65), rnorm(10, 0, 1)),
index = 1:40
)
cut_by_group(data, "AVAL", "PARAM", group, "my_new_categories")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.