Check for and report duplicated labels

Description

The function duplicated_labels can be used with “item” objects, “importer” objects or “data.set” objects to check whether items contain duplicate labels, i.e. labels that are attached to more than one code.

Usage

duplicated_labels(x)
## S3 method for class 'item'
duplicated_labels(x)
# Applicable to 'importer' objects and 'data.set' objects
## S3 method for class 'item.list'
duplicated_labels(x)

Arguments

x

an item with value labels or that contains items with value labels

Value

The function duplicate.labels returns a list with a class attribute, which allows pretty printing of duplicated value labels

Examples

x1 <- as.item(rep(1:5,4),
             labels=c(
                 A = 1,
                 A = 2,
                 B = 3,
                 B = 4,
                 C = 5
             ),
             annotation = c(
                 description="Yet another test"
)
Warning: Duplicate labels 'A' 'B'
x2 <- as.item(rep(1:4,5),
             labels=c(
                 i   = 1,
                 ii  = 2,
                 iii = 3,
                 iii = 4
                 ),
             annotation = c(
                 description="Still another test"
)
Warning: Duplicate labels 'iii'
x3 <- as.item(rep(1:2,10),
             labels=c(
                 a = 1,
                 b = 2
                 ),
             annotation = c(
                 description="Still another test"
)
duplicated_labels(x1)
A: 1, 2
B: 3, 4
ds <- data.set(x1,x2,x3)
duplicated_labels(ds)
================================================================================
 x1: 'Yet another test'
--------------------------------------------------------------------------------
  A: 1, 2
  B: 3, 4

================================================================================
 x2: 'Still another test'
--------------------------------------------------------------------------------
  iii: 3, 4
codebook(ds)
================================================================================

   x1 'Yet another test'

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

   Storage mode: integer
   Measurement: nominal

   Values and labels    N    Percent

             1   'A'    4   20.0 20.0
             2   'A'    4   20.0 20.0
             3   'B'    4   20.0 20.0
             4   'B'    4   20.0 20.0
             5   'C'    4   20.0 20.0

================================================================================

   x2 'Still another test'

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

   Storage mode: integer
   Measurement: nominal

   Values and labels    N    Percent

           1   'i'      5   25.0 25.0
           2   'ii'     5   25.0 25.0
           3   'iii'    5   25.0 25.0
           4   'iii'    5   25.0 25.0

================================================================================

   x3 'Still another test'

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

   Storage mode: integer
   Measurement: nominal

   Values and labels    N    Percent

             1   'a'   10   50.0 50.0
             2   'b'   10   50.0 50.0
nes1948.por <- unzip(system.file("anes/NES1948.ZIP",package="memisc"),
                    "NES1948.POR",exdir=tempfile())
nes1948 <- spss.portable.file(nes1948.por)
Warning: 9 variables have duplicated labels:
  v480004, v480012, v480020, v480021a, v480021b, v480033a, v480033b,
  v480034a, v480034b
duplicated_labels(nes1948)
================================================================================
 v480004: 'CODER'
--------------------------------------------------------------------------------
  NAME NOT KNOWN: 1, 2, 3, 4, 5

================================================================================
 v480012: 'WHAT TO DO W TFT-HT ACT'
--------------------------------------------------------------------------------
  HAVE HEARD OF TAFT-HARTLEY ACT: 5, 6

================================================================================
 v480020: 'CNSD VT FOR SOMEONE ELSE'
--------------------------------------------------------------------------------
  DID NOT CONSIDER ANYONE ELSE: 11, 22, 33, 44
  CONSIDERED WALLACE:           13, 23
  CONSIDERED OTHER:             14, 24
  NA:                           19, 29, 49
  CONSIDERED TRUMAN:            21, 41

================================================================================
 v480021a: 'XWHY DID NOT VT FOR HIM 1'
--------------------------------------------------------------------------------
  DISAGREED WITH PLATFORM OR POLICY - TO: 3, 4

================================================================================
 v480021b: 'XWHY DID NOT VT FOR HIM 2'
--------------------------------------------------------------------------------
  DISAGREED WITH PLATFORM OR POLICY - TO: 3, 4

================================================================================
 v480033a: 'ISSUES CONNECTED W TRMN 1'
--------------------------------------------------------------------------------
  RENT CONTROL:              1, 16, 31, 51, 66, 81
  PRICE CONTROL:             2, 17, 32, 52, 67, 82
  TAFT-HARTLEY:              3, 18, 33, 53, 68, 83
  FARM PRICES AND SUPPORT:   4, 19, 34, 54, 69, 84
  LOWER INCOME TAX:          5, 20, 35, 55, 70, 85
  CIVIL RIGHTS:              6, 21, 36, 56, 71, 86
  BALANCE BUDGET:            7, 22, 37, 57, 72, 87
  (GOVERNMENT) HOUSING:      8, 23, 38, 58, 73, 88
  DEFENSE ACTIVITY:          9, 24, 39, 59, 74, 89
  GOVERNMENT ATOMIC CONTROL: 10, 25, 40, 60, 75, 90
  NEW DEAL:                  11, 26, 41, 61, 76, 91
  MARSHALL PLAN:             12, 27, 42, 62, 77, 92
  FIRM RUSSIAN POLICY:       13, 28, 43, 63, 78, 93
  HELP ISRAEL (PALESTINE):   14, 29, 44, 64, 79, 94
  PROMOTE PEACE:             15, 30, 45, 65, 80, 95

================================================================================
 v480033b: 'ISSUES CONNECTED W TRMN 2'
--------------------------------------------------------------------------------
  RENT CONTROL:              1, 16, 31, 51, 66, 81
  PRICE CONTROL:             2, 17, 32, 52, 67, 82
  TAFT-HARTLEY:              3, 18, 33, 53, 68, 83
  FARM PRICES AND SUPPORT:   4, 19, 34, 54, 69, 84
  LOWER INCOME TAX:          5, 20, 35, 55, 70, 85
  CIVIL RIGHTS:              6, 21, 36, 56, 71, 86
  BALANCE BUDGET:            7, 22, 37, 57, 72, 87
  (GOVERNMENT) HOUSING:      8, 23, 38, 58, 73, 88
  DEFENSE ACTIVITY:          9, 24, 39, 59, 74, 89
  GOVERNMENT ATOMIC CONTROL: 10, 25, 40, 60, 75, 90
  NEW DEAL:                  11, 26, 41, 61, 76, 91
  MARSHALL PLAN:             12, 27, 42, 62, 77, 92
  FIRM RUSSIAN POLICY:       13, 28, 43, 63, 78, 93
  HELP ISRAEL (PALESTINE):   14, 29, 44, 64, 79, 94
  PROMOTE PEACE:             15, 30, 45, 65, 80, 95

================================================================================
 v480034a: 'ISSUES CONNECTED W DEWEY 1'
--------------------------------------------------------------------------------
  RENT CONTROL:              1, 16, 31, 51, 66, 81
  PRICE CONTROL:             2, 17, 32, 52, 67, 82
  TAFT-HARTLEY:              3, 18, 33, 53, 68, 83
  FARM PRICES AND SUPPORT:   4, 19, 34, 54, 69, 84
  LOWER INCOME TAX:          5, 20, 35, 55, 70, 85
  CIVIL RIGHTS:              6, 21, 36, 56, 71, 86
  BALANCE BUDGET:            7, 22, 37, 57, 72, 87
  (GOVERNMENT) HOUSING:      8, 23, 38, 58, 73, 88
  DEFENSE ACTIVITY:          9, 24, 39, 59, 74, 89
  GOVERNMENT ATOMIC CONTROL: 10, 25, 40, 60, 75, 90
  NEW DEAL:                  11, 26, 41, 61, 76, 91
  MARSHALL PLAN:             12, 27, 42, 62, 77, 92
  FIRM RUSSIAN POLICY:       13, 28, 43, 63, 78, 93
  HELP ISRAEL (PALESTINE):   14, 29, 44, 64, 79, 94
  PROMOTE PEACE:             15, 30, 45, 65, 80, 95

================================================================================
 v480034b: 'ISSUES CONNECTED W DEWEY 2'
--------------------------------------------------------------------------------
  RENT CONTROL:              1, 16, 31, 51, 66, 81
  PRICE CONTROL:             2, 17, 32, 52, 67, 82
  TAFT-HARTLEY:              3, 18, 33, 53, 68, 83
  FARM PRICES AND SUPPORT:   4, 19, 34, 54, 69, 84
  LOWER INCOME TAX:          5, 20, 35, 55, 70, 85
  CIVIL RIGHTS:              6, 21, 36, 56, 71, 86
  BALANCE BUDGET:            7, 22, 37, 57, 72, 87
  (GOVERNMENT) HOUSING:      8, 23, 38, 58, 73, 88
  DEFENSE ACTIVITY:          9, 24, 39, 59, 74, 89
  GOVERNMENT ATOMIC CONTROL: 10, 25, 40, 60, 75, 90
  NEW DEAL:                  11, 26, 41, 61, 76, 91
  MARSHALL PLAN:             12, 27, 42, 62, 77, 92
  FIRM RUSSIAN POLICY:       13, 28, 43, 63, 78, 93
  HELP ISRAEL (PALESTINE):   14, 29, 44, 64, 79, 94
  PROMOTE PEACE:             15, 30, 45, 65, 80, 95