recode2: Wrapper for 'recode' from 'car' to allow to recode multiple...

Description Usage Arguments Value Author(s) Examples

Description

Wrapper for recode from car to allow to recode multiple columns at once

Usage

1
recode2(x, vars = NULL, ...)

Arguments

x

A dataframe.

vars

A vector of variable names or numeric indexes to select the columns to recode.

...

Arguments that are passed on to recode from car (see ?recode for more info).

recodes Character string of recode specifications: see below.
as.factor.result Return a factor; default is TRUE if the column is a factor, FALSE otherwise.
as.numeric.result If TRUE (the default), and as.factor.result is FALSE, then the result will be coerced to numeric if all values in the result are numerals — i.e., represent numbers.
levels An optional argument specifying the order of the levels in the returned factor; the default is to use the sort order of the level names.
... More arguments passed to recode.

Value

A dataframe with recoded columns.

Author(s)

Mark Heckmann

Examples

1
2
3
4
5
a <- attitude
rec <- "0:50=1; 51:70=2; 60:100=3; else=NA"
recode2(a, recodes=rec)
recode2(a, vars=1:2, recodes=rec)
recode2(a, vars=c("rating", "complaints"), recodes=rec)

Example output

   rating complaints privileges learning raises critical advance
1       1          2          1        1      2        3       1
2       2          2          2        2      2        3       1
3       3          2          2        2      3        3       1
4       2          2          1        1      2        3       1
5       3          3          2        2      3        3       1
6       1          2          1        1      2        1       1
7       2          2          1        2      2        2       1
8       3          3          1        2      2        2       1
9       3          3          3        2      3        3       1
10      2          2          1        1      2        3       1
11      2          2          2        2      2        2       1
12      2          2          1        1      2        3       1
13      2          2          2        1      2        2       1
14      2          3          3        1      2        3       1
15      3          3          2        3      3        3       1
16      3          3          1        3      2        2       1
17      3          3          2        2      3        3       2
18      2          2          2        3      2        3       2
19      2          2          1        2      3        3       1
20      1          2          2        2      2        3       2
21      1          1          1        1      1        2       1
22      2          2          2        2      2        3       1
23      2          2          2        1      2        3       1
24      1          1          1        2      1        2       1
25      2          2          1        1      2        3       1
26      2          3          2        2      3        3       3
27      3          3          2        3      3        3       1
28      1          2          1        1      2        3       1
29      3          3          3        3      3        3       2
30      3          3          1        2      2        3       1
   rating complaints privileges learning raises critical advance
1       1          2         30       39     61       92      45
2       2          2         51       54     63       73      47
3       3          2         68       69     76       86      48
4       2          2         45       47     54       84      35
5       3          3         56       66     71       83      47
6       1          2         49       44     54       49      34
7       2          2         42       56     66       68      35
8       3          3         50       55     70       66      41
9       3          3         72       67     71       83      31
10      2          2         45       47     62       80      41
11      2          2         53       58     58       67      34
12      2          2         47       39     59       74      41
13      2          2         57       42     55       63      25
14      2          3         83       45     59       77      35
15      3          3         54       72     79       77      46
16      3          3         50       72     60       54      36
17      3          3         64       69     79       79      63
18      2          2         65       75     55       80      60
19      2          2         46       57     75       85      46
20      1          2         68       54     64       78      52
21      1          1         33       34     43       64      33
22      2          2         52       62     66       80      41
23      2          2         52       50     63       80      37
24      1          1         42       58     50       57      49
25      2          2         42       48     66       75      33
26      2          3         66       63     88       76      72
27      3          3         58       74     80       78      49
28      1          2         44       45     51       83      38
29      3          3         71       71     77       74      55
30      3          3         39       59     64       78      39
   rating complaints privileges learning raises critical advance
1       1          2         30       39     61       92      45
2       2          2         51       54     63       73      47
3       3          2         68       69     76       86      48
4       2          2         45       47     54       84      35
5       3          3         56       66     71       83      47
6       1          2         49       44     54       49      34
7       2          2         42       56     66       68      35
8       3          3         50       55     70       66      41
9       3          3         72       67     71       83      31
10      2          2         45       47     62       80      41
11      2          2         53       58     58       67      34
12      2          2         47       39     59       74      41
13      2          2         57       42     55       63      25
14      2          3         83       45     59       77      35
15      3          3         54       72     79       77      46
16      3          3         50       72     60       54      36
17      3          3         64       69     79       79      63
18      2          2         65       75     55       80      60
19      2          2         46       57     75       85      46
20      1          2         68       54     64       78      52
21      1          1         33       34     43       64      33
22      2          2         52       62     66       80      41
23      2          2         52       50     63       80      37
24      1          1         42       58     50       57      49
25      2          2         42       48     66       75      33
26      2          3         66       63     88       76      72
27      3          3         58       74     80       78      49
28      1          2         44       45     51       83      38
29      3          3         71       71     77       74      55
30      3          3         39       59     64       78      39

ryouready documentation built on May 1, 2019, 8:39 p.m.