# fctr: Convert labelled variable to factor In expss: Tables, Labels and Some Useful Functions from Spreadsheets and 'SPSS' Statistics

## Description

`fctr` converts variable to factor. It force labels usage as factor labels for labelled variables even if 'expss.enable_value_labels_support' set to 0. For other types of variables base factor is called. Factor levels are constructed as values labels. If label doesn't exist for particular value then this value remain as is - so there is no information lost. This levels look like as "Variable_label|Value label" if argument `prepend` set to TRUE.

## Usage

 `1` ```fctr(x, ..., drop_unused_labels = FALSE, prepend_var_lab = TRUE) ```

## Arguments

 `x` a vector of data with labels. `...` optional arguments for `factor` `drop_unused_labels` logical. Should we drop unused value labels? Default is FALSE. `prepend_var_lab` logical. Should we prepend variable label before value labels? Default is TRUE.

## Value

an object of class factor. For details see base factor documentation.

values2labels, names2labels, val_lab, var_lab. Materials for base functions: `factor`, `as.factor`, `ordered`, `as.ordered`

## Examples

 ```1 2 3 4 5 6 7 8``` ```data(mtcars) var_lab(mtcars\$am) = "Transmission" val_lab(mtcars\$am) = c(automatic = 0, manual=1) summary(lm(mpg ~ am, data = mtcars)) # no labels summary(lm(mpg ~ fctr(am), data = mtcars)) # with labels summary(lm(mpg ~ fctr(unvr(am)), data = mtcars)) # without variable label ```

### Example output

```Call:
lm(formula = mpg ~ am, data = mtcars)

Residuals:
Min      1Q  Median      3Q     Max
-9.3923 -3.0923 -0.2974  3.2439  9.5077

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)   17.147      1.125  15.247 1.13e-15 ***
am             7.245      1.764   4.106 0.000285 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 4.902 on 30 degrees of freedom
Multiple R-squared:  0.3598,	Adjusted R-squared:  0.3385
F-statistic: 16.86 on 1 and 30 DF,  p-value: 0.000285

Call:
lm(formula = mpg ~ fctr(am), data = mtcars)

Residuals:
Min      1Q  Median      3Q     Max
-9.3923 -3.0923 -0.2974  3.2439  9.5077

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)                   17.147      1.125  15.247 1.13e-15 ***
fctr(am)Transmission|manual    7.245      1.764   4.106 0.000285 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 4.902 on 30 degrees of freedom
Multiple R-squared:  0.3598,	Adjusted R-squared:  0.3385
F-statistic: 16.86 on 1 and 30 DF,  p-value: 0.000285

Call:
lm(formula = mpg ~ fctr(unvr(am)), data = mtcars)

Residuals:
Min      1Q  Median      3Q     Max
-9.3923 -3.0923 -0.2974  3.2439  9.5077

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)            17.147      1.125  15.247 1.13e-15 ***
fctr(unvr(am))manual    7.245      1.764   4.106 0.000285 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 4.902 on 30 degrees of freedom
Multiple R-squared:  0.3598,	Adjusted R-squared:  0.3385
F-statistic: 16.86 on 1 and 30 DF,  p-value: 0.000285
```

expss documentation built on Jan. 8, 2021, 5:38 p.m.