| ordervar | R Documentation |
Reorders variables in an explicit data frame or the active R4VN data frame.
ordervar(..., data = NULL, before = NULL, after = NULL, last = FALSE)
... |
Variables to move. For backward compatibility, an explicit data frame may be the first unnamed argument. |
data |
Optional explicit data frame object. |
before |
Optional anchor variable. |
after |
Optional anchor variable. |
last |
Logical; move variables to the end. |
The edited data frame invisibly.
d <- data.frame(age = 1, sex = 2, id = 3, bmi = 4)
usedf(d, quiet = TRUE)
ordervar(id, sex)
ordervar(bmi, after = age)
# Extended usage examples
d <- data.frame(age = 1, sex = 2, id = 3, bmi = 4, outcome = 5)
# Move variables to the beginning
d1 <- d; ordervar(d1, id, outcome)
# Move before or after an anchor
d2 <- d; ordervar(d2, outcome, before = age)
d3 <- d; ordervar(d3, bmi, after = age)
# Move to the end
d4 <- d; ordervar(d4, id, last = TRUE)
# Use a range or wildcard
d5 <- data.frame(id = 1, q1 = 2, q2 = 3, q3 = 4, age = 5)
ordervar(d5, q1:q3, last = TRUE)
# Active-data syntax
usedf(d, quiet = TRUE); ordervar(id, outcome)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.