recode: recode

Description Usage Arguments Value Author(s) Examples

View source: R/recode.R

Description

recode is a function recode a variable into recoded groups.

Usage

1
2
3
recode(x, groups, Labels = NULL, na.val = "others",
  method = c("ranges", "substrs", "elements")[1], mode = c("numeric",
  "character", "datetime")[1], tsFormat = "ymd")

Arguments

x

is a vector which could be numeric, datetime or character

groups

is simlar with L in legal_set, but different in that for elements and substrs it should be a list

Labels

defines the labels for the returned value

na.val

label that are not included in the groups.

method

could be ranges, substrs and elements

mode

could be numeric, character or datetime

tsFormat

tsFormat to define the ts variable.

Value

a recoded vector

Author(s)

sontron

Examples

1
2
3
4
5
6
7
8
9
x=rnorm(100)
recode(x,groups=c('(-Inf,0]','(0,Inf)'),Labels=c('negative_value','positive_value'),method='ranges',mode='numeric')
x=sample(letters[1:5],100,rep=T)
recode(x,groups=list(c('a','b'),c('c','d','e')),Labels=c('a-b','c-e'),method='elements',mode='character')
x=c('google','goodbye','doodle','doodoge','go!','bad')
recode(x,groups=list(c('goo'),c('doo')),Labels=c('include_goo','include_doo'),method='substrs',mode='character')

x=apply(expand.grid(2018,3:5,1:30),1,function(x)paste(x,collapse='-'))
recode(x,groups=c('[2018-3-1,2018-3-31]','[2018-4-1,2018-4-30]','[2018-5-1,2018-5-31]'),Labels=c('march','april','may'),method='ranges',mode='datetime',tsFormat='ymd')

sontron/madis documentation built on March 23, 2021, 10:17 p.m.