simple_recode: Do a simple recode via pattern for data

Description Usage Arguments Value See Also

View source: R/toolkits.R

Description

A function to re-encode data by using a map. Patterns are accepted. unmentioned data are left intact.

Method for class data.frame supports a robust replacement for data by providing relevant map in the form of var = map.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
simple_recode(...)

## S3 method for class 'data.frame'
simple_recode(.data, ..., ignore.case = FALSE,
  perl = TRUE)

## Default S3 method:
simple_recode(x, map, as = c("as_is", "numeric",
  "factor", "character", "logical"), ignore.case = FALSE, perl = TRUE,
  ...)

Arguments

...

For data.frame: Replacement in the form of var = map. Maps must follow the syntax stipulated in the map parameter.

For default method: Additional parameters passed to factor()

.data

A data frame to modify

ignore.case, perl

Parameters passed to gsub().

perl

Are patterns follow the Perl-style regular expression.

x

a vector

map

A map.

Map can be a list in the form of recoded_text = c(to_be_recoded_text)

Or as a data frame having 2 columns named "from" and "to".

as

A character string defining the post-recoded data type of x. Default is keeping as-is.

ignore.case

Specify whether the pattern is case-insensitive. Default is FALSE (case sensitive)

Value

A data frame with recoded variables.

If input is a vector, return a vector of the same length.

If input is a data frame, return a data frame with relevant variables recoded.

See Also

regex case_when


lampk/C306 documentation built on Sept. 11, 2019, 8:03 a.m.