| keepvar | R Documentation |
Keeps variables or observations in an explicit data frame or active data.
keepvar(..., data = NULL, obs = NULL)
... |
Variable selectors. For backward compatibility, an explicit data frame may be the first unnamed argument. |
data |
Optional explicit data frame object. |
obs |
Optional observations to keep. |
The edited data frame invisibly.
d <- data.frame(
id = 1:5,
age = c(10, 20, NA, 40, 50),
sex = c("M", "F", "F", "M", "F"),
score_a = 1:5,
score_b = 6:10
)
# Each explicit-data example uses its own copy because keepvar()
# intentionally edits the supplied object.
d1 <- d
keepvar(d1, id, age, sex)
d2 <- d
keepvar(d2, id:sex)
d3 <- d
keepvar(d3, id, "score_*")
d4 <- d
keepvar(d4, obs = age >= 18)
d5 <- d
keepvar(d5, id, age, obs = !missing(age))
d6 <- d
keepvar(d6, obs = c(1, 3, 5))
# Active-data syntax
active_d <- d
usedf(active_d, quiet = TRUE)
keepvar(id, age, obs = age >= 18)
usedf(clear = TRUE, quiet = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.