to_labelled: Convert to labelled

Description Usage Arguments Note Author(s) Examples

Description

Reverses the process from from_labelled, by attempting to create labelled variables in place of factor, and adding labels to each variable.

Usage

1
2
3
4
5
6
7
to_labelled(x, label = NULL)

## S3 method for class 'factor'
to_labelled(x, label = NULL)

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

Arguments

x

A factor or data.frame.

label

Optional: Set a label when converting a vector to

...

Ignored. labelled.

Note

Because of a limitation in ReadStat (it can't write strings longer than 256 characters), write_data will write the long strings as a separate .Rdata file. If you use read_data, you will get them back.

Author(s)

Kristian D. Olsen

Examples

1
2
3
4
5
6
7
8
levs <- c("Agree", "Neutral", "Disagree", "Don't know")
var <- factor(levs[c(1, 3, 4)], levels = levs)

# Works with just the factor
to_labelled(var)

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

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