Learn R Programming

clintools (version 0.9.10.1)

recol: Reorder column (recol)

Description

recol() is a small function which can rename columns and change factors to relevant input

Usage

recol(df, old, new, factors=NULL, remove=TRUE, na=NA)

Value

Returns the dataframe with new columns.

Arguments

df

dataframe. (df)

old

old column name. (string)

new

new column name. (string)

factors

Named list of factors. If no names then just in alphabetical order (named list)

remove

remove old column from dataframe (boolian)

na

the na.strings (list)

Examples

Run this code
if (FALSE) {
   # NUMERIC VARIABLE
   df <- recol(df, "X5d_55_Alcohol_127", "Alcohol")
   # FACTOR VARIABLE
   df <- recol(df, "X5d_55_Alcohol_127", "Alcohol", factors=c("No","Yes"))
}

Run the code above in your browser using DataLab