value.filter {memisc}R Documentation

Value Filters

Description

Value filters, that is objects that inherit from class "value.filter", are a mechanism to distinguish between valid codes of a survey item and codes that are considered to be missing, such as the codes for answers like "don't know" or "answer refused".

Value filters are optional slot values of "item" objects. They determine which codes of "item" objects are replaced by NA when they are coerced into a vector or a factor.

There are three (sub)classes of value filters: "missing.values", which specify individual missing values and/or a range of missing values; "valid.values", which specify individual valid values (that is, all other values of the item are considered as missing); "valid.range", which specify a range of valid values (that is, all values outside the range are considered as missing). Value filters of class "missing.values" correspond to missing-values declarations in SPSS files, imported by spss.fixed.file, spss.portable.file, or spss.system.file.

Value filters also can be updated using the + and - operators.

Usage

value.filter(x)

missing.values(x)
missing.values(x)<-value

valid.values(x)
valid.values(x)<-value

valid.range(x)
valid.range(x)<-value

is.valid(x)
nvalid(x)
is.missing(x)
include.missings(x,mark="*")

Arguments

x, value

objects of the appropriate class.

mark

a character string, used to pasted to value labels of x (if present).

Value

value.filter(x), missing.values(x), valid.values(x), and valid.range(x), return the value filter associated with x, an object of class "value.filter", that is, of class "missing.values", "valid.values", or "valid.range", respectively.

is.missing(x) returns a logical vector indicating for each element of x whether it is a missing value or not. is.valid(x) returns a logical vector indicating for each element of x whether it is a valid value or not. nvalid(x) returns the number of elements of x that are valid.

For convenience, is.missing(x) and is.valid(x) also work for atomic vectors and factors, where they are equivalent to is.na(x) and !is.na(x). For atomic vectors and factors, nvalid(x) returns the number of elements of x for which !is.na(x) is TRUE.

include.missings(x,...) returns a copy of x that has all values declared as valid.

Examples

x <- rep(c(1:4,8,9),2,length=60)
labels(x) <- c(
    a=1,
    b=2,
    c=3,
    d=4,
    dk=8,
    refused=9
    )
missing.values(x) <- 9
missing.values(x)
missing.values(x) <- missing.values(x) + 8
missing.values(x)
missing.values(x) <- NULL
missing.values(x)
missing.values(x) <- list(range=c(8,Inf))
missing.values(x)
valid.values(x)
print(x)
is.missing(x)
is.valid(x)
as.factor(x)
as.factor(include.missings(x))
as.integer(x)
as.integer(include.missings(x))

[Package memisc version 0.99.31.7 Index]