value-filters: Value Filters

Description Usage Arguments Value Examples

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Example output

Loading required package: lattice
Loading required package: MASS

Attaching package: 'memisc'

The following objects are masked from 'package:stats':

    contr.sum, contr.treatment, contrasts

The following object is masked from 'package:base':

    as.array

9
9, 8
NULL
8-Inf
1, 2, 3, 4
 [1]        a        b        c        d      *dk *refused        a        b
 [9]        c        d      *dk *refused        a        b        c        d
[17]      *dk *refused        a        b        c        d      *dk *refused
[25]        a        b        c        d      *dk *refused        a        b
[33]        c        d      *dk *refused        a        b        c        d
[41]      *dk *refused        a        b        c        d      *dk *refused
[49]        a        b        c        d      *dk *refused        a        b
[57]        c        d      *dk *refused
 [1] FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE
[13] FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE
[25] FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE
[37] FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE
[49] FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE
 [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
[13]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
[25]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
[37]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
[49]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
 [1] a    b    c    d    <NA> <NA> a    b    c    d    <NA> <NA> a    b    c   
[16] d    <NA> <NA> a    b    c    d    <NA> <NA> a    b    c    d    <NA> <NA>
[31] a    b    c    d    <NA> <NA> a    b    c    d    <NA> <NA> a    b    c   
[46] d    <NA> <NA> a    b    c    d    <NA> <NA> a    b    c    d    <NA> <NA>
Levels: a b c d
 [1] a        b        c        d        *dk      *refused a        b       
 [9] c        d        *dk      *refused a        b        c        d       
[17] *dk      *refused a        b        c        d        *dk      *refused
[25] a        b        c        d        *dk      *refused a        b       
[33] c        d        *dk      *refused a        b        c        d       
[41] *dk      *refused a        b        c        d        *dk      *refused
[49] a        b        c        d        *dk      *refused a        b       
[57] c        d        *dk      *refused
Levels: a b c d *dk *refused
 [1]  1  2  3  4 NA NA  1  2  3  4 NA NA  1  2  3  4 NA NA  1  2  3  4 NA NA  1
[26]  2  3  4 NA NA  1  2  3  4 NA NA  1  2  3  4 NA NA  1  2  3  4 NA NA  1  2
[51]  3  4 NA NA  1  2  3  4 NA NA
 [1] 1 2 3 4 8 9 1 2 3 4 8 9 1 2 3 4 8 9 1 2 3 4 8 9 1 2 3 4 8 9 1 2 3 4 8 9 1 2
[39] 3 4 8 9 1 2 3 4 8 9 1 2 3 4 8 9 1 2 3 4 8 9

memisc documentation built on May 2, 2019, 5:45 p.m.

Related to value-filters in memisc...