Skip to content
Back to formatted view

Raw Message

Message-ID: <FB454C9C2759D64BA12708C3073C30BB81F782B7F4@NUEW-EXMBCRB1.gfk.com>
Date: 2015-08-04T14:40:46Z
From: Conklin, Mike (GfK)
Subject: attributes in dplyr and haven

I read in spss files using haven's read_spss. Each column then gets attributes assigned named
label - a long description of the variable
class -" labelled"
labels --- answer labels i.e. 1=Male, 2=Female
 example -
> attributes(KPTV[[3]])
$label
[1] "DERIVED: Survey language"

$class
[1] "labelled"

$labels
English Spanish 
      1       2 

However, if I subset the data.frame  e.g. MassTV<-KPTV[row selection logic,] the label attribute disappears

attributes(MassTV[[3]])
$labels
English Spanish 
      1       2 

$class
[1] "labelled"

If I use dplyr to filter the data I simply get an ERROR that the label attribute is not supported.

> MassTV<-filter(KPTV,KPTV$MNO %in% KPMass$`KPMain$mno`)
Error: column 'MNO' of type numeric has unsupported attributes: label

Any ideas on how I can preserve the label attribute (i.e. the long description of the variable name?)

Thanks for any help,

Mike

--
W. Michael Conklin
Executive Vice President
Marketing & Data Sciences - North America
GfK | 8401 Golden Valley Road | Minneapolis | MN | 55427
mike.conklin at gfk.com 
T +1 763 417 4545 | M +1 612 567 8287 
www.gfk.com