items: Survey Items

Description Usage Arguments See Also Examples

Description

Objects of class item are data vectors with additional information attached to them like “value labels” and “user-defined missing values” known from software packages like SPSS or Stata.

Usage

 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## The constructor for objects of class "item"
## more convenient than new("item",...)
## S4 method for signature 'numeric'
as.item(x,
  labels=NULL,  missing.values=NULL,
  valid.values=NULL,  valid.range=NULL,
  value.filter=NULL,  measurement=NULL,
  annotation=attr(x,"annotation"), ...
  )
## S4 method for signature 'character'
as.item(x,
  labels=NULL,  missing.values=NULL,
  valid.values=NULL,  valid.range=NULL,
  value.filter=NULL,  measurement=NULL,
  annotation=attr(x,"annotation"), ...
  )

## S4 method for signature 'logical'
as.item(x,...)
# x is first coerced to integer,
# arguments in ... are then passed to the "numeric"
# method.

## S4 method for signature 'factor'
as.item(x,...)
## S4 method for signature 'ordered'
as.item(x,...)
## S4 method for signature 'POSIXct'
as.item(x,...)

## S4 method for signature 'double.item'
as.item(x,
  labels=NULL,  missing.values=NULL,
  valid.values=NULL,  valid.range=NULL,
  value.filter=NULL,  measurement=NULL,
  annotation=attr(x,"annotation"), ...
  )

## S4 method for signature 'integer.item'
as.item(x,
  labels=NULL,  missing.values=NULL,
  valid.values=NULL,  valid.range=NULL,
  value.filter=NULL,  measurement=NULL,
  annotation=attr(x,"annotation"), ...
  )

## S4 method for signature 'character.item'
as.item(x,
  labels=NULL,  missing.values=NULL,
  valid.values=NULL,  valid.range=NULL,
  value.filter=NULL,  measurement=NULL,
  annotation=attr(x,"annotation"), ...
  )

## S4 method for signature 'datetime.item'
as.item(x,
  labels=NULL,  missing.values=NULL,
  valid.values=NULL,  valid.range=NULL,
  value.filter=NULL,  measurement=NULL,
  annotation=attr(x,"annotation"), ...
  )

Arguments

x

for as.item methods, any atomic vector; for the as.character, as.factor, as.integer, as.double, a vector with class "item"; for the unique, summary, str, print, [, and <- methods, a vector with class labelled.

labels

a named vector of the same mode as x.

missing.values

either a vector of the same mode as x, or a list with components "values", vector of the same mode as x (which defines individual missing values) and "range" a matrix with two rows with the same mode as x (which defines a range of missing values), or an object of class "missing.values".

valid.values

either a vector of the same mode as x, defining those values of x that are to be considered as valid, or an object of class "valid.values".

valid.range

either a vector of the same mode as x and length 2, defining a range of valid values of x, or an object of class "valid.range".

value.filter

an object of class "value.filter", that is, of classes "missing.values", "valid.values", or "valid.range".

measurement

level of measurement; one of "nominal", "ordinal", "interval", or "ratio".

annotation

a named character vector, or an object of class "annotation"

...

further arguments, ignored.

See Also

annotation labels value.filter

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  x <- as.item(rep(1:5,4),
      labels=c(
          "First"      = 1,
          "Second"     = 2,
          "Third"      = 3,
          "Fourth"     = 4,
          "Don't know" = 5
        ),
      missing.values=5,
      annotation = c(
        description="test"
      ))
  str(x)
  summary(x)
  as.numeric(x)

  test <- as.item(rep(1:6,2),labels=structure(1:6,
                                      names=letters[1:6]))
  test
  test == 1
  test != 1
  test == "a"
  test != "a"
  test == c("a","z")
  test != c("a","z")
  test 
  test 

  codebook(test)

  Test <- as.item(rep(letters[1:6],2),
                    labels=structure(letters[1:6],
                                     names=LETTERS[1:6]))
  Test
  Test == "a"
  Test != "a"
  Test == "A"
  Test != "A"
  Test == c("a","z")
  Test != c("a","z")
  Test 
  Test 

  as.factor(test)
  as.factor(Test)
  as.numeric(test)
  as.character(test)
  as.character(Test)

  as.data.frame(test)[[1]]

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

 Nmnl. item w/ 5 labels for 1,2,3,... + ms.v.  int [1:20] 1 2 3 4 5 1 2 3 4 5 ...
      First      Second       Third      Fourth *Don't know 
          4           4           4           4           4 
 [1]  1  2  3  4 NA  1  2  3  4 NA  1  2  3  4 NA  1  2  3  4 NA

Item (measurement: nominal, type: integer, length = 12) 

 [1:12] a b c d e f a b c d e f
 [1]  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
 [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [1]  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
 [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [1]  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
 [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE

Item (measurement: nominal, type: integer, length = 12) 

 [1:12] a b c d e f a b c d e f

Item (measurement: nominal, type: integer, length = 12) 

 [1:12] a b c d e f a b c d e f
================================================================================

   test

--------------------------------------------------------------------------------

   Storage mode: integer
   Measurement: nominal

   Values and labels    N    Percent 
                                     
             1   'a'    2   16.7 16.7
             2   'b'    2   16.7 16.7
             3   'c'    2   16.7 16.7
             4   'd'    2   16.7 16.7
             5   'e'    2   16.7 16.7
             6   'f'    2   16.7 16.7


Item (measurement: nominal, type: character, length = 12) 

 [1:12] A B C D E F A B C D E F
 [1]  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
 [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
 [1]  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
 [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE

Item (measurement: nominal, type: character, length = 12) 

 [1:12] A B C D E F A B C D E F

Item (measurement: nominal, type: character, length = 12) 

 [1:12] A B C D E F A B C D E F
 [1] a b c d e f a b c d e f
Levels: a b c d e f
 [1] A B C D E F A B C D E F
Levels: A B C D E F
 [1] 1 2 3 4 5 6 1 2 3 4 5 6
 [1] "a" "b" "c" "d" "e" "f" "a" "b" "c" "d" "e" "f"
 [1] "A" "B" "C" "D" "E" "F" "A" "B" "C" "D" "E" "F"
 [1] a b c d e f a b c d e f
Levels: a b c d e f

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

Related to items in memisc...