rename_variable: Rename variables in a data frame.

Description Usage Arguments Details Value Examples

View source: R/utilities.R

Description

This function renames variables in a data frame.

Usage

1

Arguments

x

A data frame.

search

A character vector representing the variable names to be renamed.

replace

A character vector representing the new names for those variables identified in the search argument.

Details

Other capl functions called by this function include: validate_character().

Value

Returns a data frame with the renamed variables (if variables in the search argument are successfully found and renamed).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
capl_demo_data <- get_capl_demo_data(n = 25)

str(capl_demo_data[, 1:2])

# 'data.frame':	25 obs. of  2 variables:
# $ age   : int  11 9 10 11 9 8 11 9 10 12 ...
# $ gender: chr  "Female" "Girl" "Girl" "f" ...

capl_demo_data <- rename_variable(
  x = capl_demo_data, 
  search = c("age", "gender"),
  replace = c("hello", "world")
)

str(capl_demo_data[, 1:2])

# 'data.frame':	25 obs. of  2 variables:
# $ hello: int  11 9 10 11 9 8 11 9 10 12 ...
# $ world: chr  "Female" "Girl" "Girl" "f" ...

capl documentation built on March 16, 2021, 9:06 a.m.