reorderColumns: Reorder the columns in a data.frame

View source: R/utils.R

reorderColumnsR Documentation

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)

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.

Value

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

Examples

{
  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))
}


datarobot documentation built on May 29, 2024, 4:36 a.m.