selectBy: Select a subset of rows (subjects) meeting one or more...

selectByR Documentation

Select a subset of rows (subjects) meeting one or more criteria for columns

Description

Select a subset of a data.frame or matrix for columns meeting specific criteria. Can do logical AND (default) or OR of the resulting search. Columns (variables) are specified by name and the conditions to meet include equality, less than, more than or inequality to a specified set of values. SplitBy creates new dichotomous variables based on the splitting criteria.

Usage

selectBy(x, by)
splitBy(x, by, new=FALSE)

Arguments

x

A data frame or matrix

by

A quote delimited string of variables and criteria values. Multiple variables may be separated by commas (default to AND)

new

If true, return a new data frame with just the dichotomous variables otherwise concatenate the new variables to the right margin of x

Details

Two relatively trivial functions to help those less familiar with the subset function or how to use [] to select variables.

Value

The subset of the original data.frame with just the cases that meet the criteria (selectBy) or new variables, recoded 0,1

selectBy is equivalent to subsetting x by an x value: small <- x[x[by=criterion]] or the subset function small <- subset(x, x$variable == value)

Author(s)

William Revelle

See Also

vJoin for another data manipulation function.

Examples

testand <- selectBy(attitude, 'rating < 70 & complaints > 60')  #AND
dim(testand)
testor <- selectBy(attitude, 'rating < 60 | complaints > 60')  #OR
dim(testor)
test <- splitBy(attitude, 'rating > 70 , complaints > 60')  
psych::headTail(test)

psychTools documentation built on May 29, 2024, 9:47 a.m.