Description Usage Arguments Source Examples
MoveFront
moves variables to the front of a data frame.
1 |
data |
a data frame object containing the variable you want to move. |
Var |
a character vector naming the variables you would like to move to the front of the data frame. The order of the variables should match the order you want them to have in the data frame, i.e. the first variable in the vector will be the first variable in the data frame. |
exact |
logical. If |
ignore.case |
logical. If |
fixed |
logical. If |
Based primarily on a Stack Overflow answer written by rcs: http://stackoverflow.com/questions/3369959/moving-columns-within-a-data-frame-without-retyping.
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 | # Create fake data
A <- B <- C <- 1:50
OldOrder <- data.frame(A, B, C)
# Move C to front
NewOrder1 <- MoveFront(OldOrder, "C")
names(NewOrder1)
# Move B and A to the front
NewOrder2 <- MoveFront(OldOrder, c("B", "A"))
names(NewOrder2)
## Non-exact matching (example from Felix Hass)
# Create fake data
df <- data.frame(dummy = c(1,0), Name = c("Angola", "Chad"),
DyadName = c("Government of Angola - UNITA",
"Government of Chad - FNT"),
Year = c("2002", "1992"))
df <- MoveFront(df, c("Name", "Year"), exact = FALSE)
names(df)
df <- MoveFront(df, c("Name", "Year"), exact = TRUE)
names(df)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.