Learn R Programming

psychTools (version 2.3.6)

recode: Recode variable values to new values

Description

Given a set of numeric codes, change their values to different values given a mapping function

Usage

recode(x, where, isvalue, newvalue)

Value

The reordered daa

Arguments

x

A matrix or data frame of numeric values

where

The column numbers to fix

isvalue

A vector of values to change

newvalue

A vector of the new values

Author

William Revelle

Details

Sometime, data are entered as levels in an incorrect order. Once converted to numeric values, this can lead to confusion. recoding of the data to the correct order is straightforward, if tedious.

Examples

Run this code
temp <- bfi[1:100,1:5]
isvalue <- 1:6
newvalue <- psych::cs(one,two,three,four,five,six)
newtemp <- recode(temp,1:5,isvalue,newvalue)
newtemp  #characters
temp.num <- psych::char2numeric(newtemp) #convert to numeric
temp.num  #notice the numerical values have changed
new.temp.num <- recode(temp.num, 1:5, isvalue=c(3,6,5,2,1,4), newvalue=1:6)
#note that because char2numeric works colum wise, this will fail for small sets

Run the code above in your browser using DataLab