from_labelled: Convert from labelled data

Description Usage Arguments Note Author(s) Examples

Description

When reading SPSS files with read_data, the output contains vectors of class labelled. This function extracts the labels and attaches them as an attribute (by the same name) to the data, and converts any labelled variables into factors.

Usage

1
2
3
4
5
6
7
from_labelled(x)

## S3 method for class 'labelled'
from_labelled(x)

## S3 method for class 'data.frame'
from_labelled(x)

Arguments

x

A labelled vector or data.frame containing it.

Note

data.table input returns a copy of the data.table.

Author(s)

Kristian D. Olsen

Examples

1
2
3
4
5
6
7
8
vals <- c("Agree", "Neutral", "Disagree", "Don't know")
var <- haven::labelled(c(1, 5), labels = setNames(1:4, vals))

# Works with just the labelled vector
from_labelled(var)

# And a data.frame containing labelled vectors
from_labelled(as.data.frame(var))$var

itsdalmo/seamless documentation built on May 18, 2019, 7:11 a.m.