Learn R Programming

mvbutils (version 2.5.4)

warn.and.subset: Extract subset and warn about omitted cases

Description

Extract row-subset of a data.frame according to a condition. If any cases (rows) are omitted, they are listed with a warning. Rows where the condition gives NA are omitted.

Usage

# This is the obligatory format, and is not very useful; look at EXAMPLES instead
warn.and.subset(x, cond,
    mess.head=deparse( substitute( x), width.cutoff=20, control=NULL, nlines=1),
    mess.cond=deparse( substitute( cond), width.cutoff=40, control=NULL, nlines=1),
    row.info=rownames( x), sub=TRUE)

Arguments

x
data.frame
cond
expression to evaluate in the context of data.frame. If sub=TRUE (the default), this will be substituted, so . If sub=FALSE, you can use a pre-assigned expression; in that case, you had better set mess.cond
mess.head
description of data.frame (e.g. its name) for use in a warning.
mess.cond
description of the desired condition for use in a warning.
row.info
character vector that will describe rows; omitted elements appear in the warning
sub
should cond be treated as a literal expression to be evaluated, or as a pre-computed logical index?

Value

  • The subsetted data.frame.

See Also

%where.warn% which is a less-flexible way of doing the same thing

Examples

Run this code
df <- data.frame( a=1:3, b=letters[1:3])
df1 <- warn.and.subset( df, a %% 2 == 1, 'Boring example data.frame', 'even-valued "a"')
condo <- quote( a %% 2 == 1)
df2 <- warn.and.subset( df, condo, 'Same boring data.frame', deparse( condo), sub=FALSE)

Run the code above in your browser using DataLab