Learn R Programming

report (version 0.4.0)

data_rename: Convenient dataframe manipulation functionalities

Description

Safe and intuitive functions to manipulate dataframes.

Usage

data_rename(data, pattern, replacement, safe = TRUE)

data_findcols(data, pattern = NULL, starts_with = NULL, ends_with = NULL)

data_remove(data, pattern)

data_reorder(data, cols, safe = TRUE)

data_addprefix(data, pattern)

data_addsuffix(data, pattern)

Arguments

data

Dataframe.

pattern, replacement, starts_with, ends_with

Character strings.

safe

Do not throw error if for instance the variable to be renamed/removed doesn't exist.

cols

Vector of column names.

Value

A modified data frame.

Examples

Run this code
# NOT RUN {
library(report)

# Rename columns
data_rename(iris, "Sepal.Length", "length")
# data_rename(iris, "FakeCol", "length", safe=FALSE)  # This fails
data_rename(iris, "FakeCol", "length") # This doesn't
data_rename(iris, c("Sepal.Length", "Sepal.Width"), c("length", "width"))

# Find columns names by pattern
data_findcols(iris, starts_with = "Sepal")
data_findcols(iris, ends_with = "Width")
data_findcols(iris, pattern = "\\.")

# Remove columns
data_remove(iris, "Sepal.Length")

# Reorder columns
data_reorder(iris, c("Species", "Sepal.Length"))
data_reorder(iris, c("Species", "dupa"))

# Add prefix / suffix
data_addprefix(iris, "NEW_")
data_addsuffix(iris, "_OLD")
# }

Run the code above in your browser using DataLab