[R] attributes in dplyr and haven

Conklin, Mike (GfK) Mike.Conklin at gfk.com
Tue Aug 4 16:40:46 CEST 2015


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 



More information about the R-help mailing list