Learn R Programming

datarobot (version 2.18.6)

reorderColumns: Reorder the columns in a data.frame

Description

This function reorders columns in a data.frame without relying on dplyr or data.table. You only need to specify the columns that should be moved; all others will be slotted in the gaps. Invalid columns are ignored.

Usage

reorderColumns(df, vars)

Value

A copy of the input data.frame, with columns rearranged per vars

Arguments

df

data.frame with named columns.

vars

integer. named vector where the names represent column names in df that should be moved. The value of each item is the new location of that column.

Examples

Run this code
{
  df <- data.frame(Time=c(1,2), In=c(2,3), Out=c(3,4), Files=c(4,5))
  datarobot:::reorderColumns(df, c("In" = 3, "Time" = 4))
}

Run the code above in your browser using DataLab