Learn R Programming

psych (version 1.0-92)

scrub: A utility for basic data cleaning. Changes values outside of minimum and maximum limits to NA

Description

A tedious part of data analysis is addressing the problem of miscoded data that needs to be converted to NA. For a given data.frame or matrix, scrub will set all values of columns from=from to to=to that are less than a set (vector) of min values or more than a vector of max values to NA.

Usage

scrub(x, where, min, max,isvalue)

Arguments

x
a data frame or matrix
where
The variables to examine. (Can be by name or by column number)
min
a vector of minimum values that are acceptable
max
a vector of maximum values that are acceptable
isvalue
a vector of values to be converted to NA (one per variable)

Value

  • The corrected data frame.

Details

Solves a tedious problem that can be done directly but that is sometimes awkward.

See Also

reverse.code, rescale for other simple utilities.

Examples

Run this code
x <- matrix(1:150,ncol=10,byrow=TRUE)
#get rid of a complicated set of cases
y <- scrub(x,where=2:4,min=c(20,30,40),max= c(120,110,100),isvalue= c(32,43,54))
y

Run the code above in your browser using DataLab