move columns to the start of a data frame or matrix

moveColumnsToFront(x, columns = NULL)

Arguments

x

data frame

columns

vector of column names

Value

data frame or matrix with columns being the leftmost columns

Examples

x <- data.frame(a = 1:5, b = 2:6, c = 3:7) moveColumnsToFront(x, "b")
#> b a c #> 1 2 1 3 #> 2 3 2 4 #> 3 4 3 5 #> 4 5 4 6 #> 5 6 5 7
moveColumnsToFront(x, c("b", "a"))
#> b a c #> 1 2 1 3 #> 2 3 2 4 #> 3 4 3 5 #> 4 5 4 6 #> 5 6 5 7