inum: Coerse Variables in Data Frames to 'enum' or 'interval'

Description Usage Arguments Details Value Examples

View source: R/inum.R

Description

Represents elements of a data frame as enum or interval.

Usage

1
2
3
4
5
inum(object, nmax = 20, ...)
## S3 method for class 'data.frame'
inum(object, nmax = 20, ignore = NULL, 
     total = FALSE, weights = NULL, as.interval = "",
     complete.cases.only = FALSE, meanlevels = FALSE, ...)

Arguments

object

A data frame.

nmax

Maximal number of categories for each of the numeric variables.

ignore

A character vector of variable names not to be discretised.

total

A logical. TRUE means that a condensed data frame of all variables is returned, FALSE a list of discretised variables.

weights

An optional vector of weights.

as.interval

A character vector of variable names to be converted to interval instead of enum.

complete.cases.only

A logical. TRUE removes all rows with missing values.

meanlevels

A logical. TRUE, the level is the mean of the observations in the corresponding bin. The default FALSE uses the largest observation in the bin.

...

Additional arguments, currently ignored.

Details

Each variable in object is converted to enum or interval.

Value

An object of class inum, basically a list of enum or interval objects. If total = TRUE, an integer vector with a data frame as levels attribute is returned. In this case, 0 means NA.

Examples

1
2
3
4
5
6
data("iris", package = "datasets")
iris[1,1] <- NA
inum(iris, nmax = 5)
inum(iris, nmax = 5, total = TRUE)
inum(iris, nmax = 5, total = TRUE, as.interval = "Sepal.Width",
     complete.cases.only = TRUE)

Example output

$Sepal.Length
  [1] <NA> 5    5    5    5    5.6  5    5    5    5    5.6  5    5    5    6.1 
 [16] 6.1  5.6  5.6  6.1  5.6  5.6  5.6  5    5.6  5    5    5    5.6  5.6  5   
 [31] 5    5.6  5.6  5.6  5    5    5.6  5    5    5.6  5    5    5    5    5.6 
 [46] 5    5.6  5    5.6  5    7.9  6.54 7.9  5.6  6.54 6.1  6.54 5    7.9  5.6 
 [61] 5    6.1  6.1  6.1  5.6  7.9  5.6  6.1  6.54 5.6  6.1  6.1  6.54 6.1  6.54
 [76] 7.9  7.9  7.9  6.1  6.1  5.6  5.6  6.1  6.1  5.6  6.1  7.9  6.54 5.6  5.6 
 [91] 5.6  6.1  6.1  5    5.6  6.1  6.1  6.54 5.6  6.1  6.54 6.1  7.9  6.54 6.54
[106] 7.9  5    7.9  7.9  7.9  6.54 6.54 7.9  6.1  6.1  6.54 6.54 7.9  7.9  6.1 
[121] 7.9  5.6  7.9  6.54 7.9  7.9  6.54 6.1  6.54 7.9  7.9  7.9  6.54 6.54 6.1 
[136] 7.9  6.54 6.54 6.1  7.9  7.9  7.9  6.1  7.9  7.9  7.9  6.54 6.54 6.54 6.1 
Levels: 5 5.6 6.1 6.54 7.9

$Sepal.Width
  [1] 4.4 3   3.4 3.1 4.4 4.4 3.4 3.4 3   3.1 4.4 3.4 3   3   4.4 4.4 4.4 4.4
 [19] 4.4 4.4 3.4 4.4 4.4 3.4 3.4 3   3.4 4.4 3.4 3.4 3.1 3.4 4.4 4.4 3.1 3.4
 [37] 4.4 4.4 3   3.4 4.4 2.7 3.4 4.4 4.4 3   4.4 3.4 4.4 3.4 3.4 3.4 3.1 2.7
 [55] 3   3   3.4 2.7 3   2.7 2.7 3   2.7 3   3   3.1 3   2.7 2.7 2.7 3.4 3  
 [73] 2.7 3   3   3   3   3   3   2.7 2.7 2.7 2.7 2.7 3   3.4 3.1 2.7 3   2.7
 [91] 2.7 3   2.7 2.7 2.7 3   3   3   2.7 3   3.4 2.7 3   3   3   3   2.7 3  
[109] 2.7 4.4 3.4 2.7 3   2.7 3   3.4 3   4.4 2.7 2.7 3.4 3   3   2.7 3.4 3.4
[127] 3   3   3   3   3   4.4 3   3   2.7 3   3.4 3.1 3   3.1 3.1 3.1 2.7 3.4
[145] 3.4 3   2.7 3   3.4 3  
Levels: 2.7 3 3.1 3.4 4.4

$Petal.Length
  [1] 1.5  1.5  1.5  1.5  1.5  3.9  1.5  1.5  1.5  1.5  1.5  3.9  1.5  1.5  1.5 
 [16] 1.5  1.5  1.5  3.9  1.5  3.9  1.5  1.5  3.9  3.9  3.9  3.9  1.5  1.5  3.9 
 [31] 3.9  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  3.9  3.9 
 [46] 1.5  3.9  1.5  1.5  1.5  5.32 4.64 5.32 4.64 4.64 4.64 5.32 3.9  4.64 3.9 
 [61] 3.9  4.64 4.64 5.32 3.9  4.64 4.64 4.64 4.64 3.9  5.32 4.64 5.32 5.32 4.64
 [76] 4.64 5.32 5.32 4.64 3.9  3.9  3.9  3.9  5.32 4.64 4.64 5.32 4.64 4.64 4.64
 [91] 4.64 4.64 4.64 3.9  4.64 4.64 4.64 4.64 3.9  4.64 6.9  5.32 6.9  6.9  6.9 
[106] 6.9  4.64 6.9  6.9  6.9  5.32 5.32 6.9  5.32 5.32 5.32 6.9  6.9  6.9  5.32
[121] 6.9  5.32 6.9  5.32 6.9  6.9  5.32 5.32 6.9  6.9  6.9  6.9  6.9  5.32 6.9 
[136] 6.9  6.9  6.9  5.32 6.9  6.9  5.32 5.32 6.9  6.9  5.32 5.32 5.32 6.9  5.32
Levels: 1.5 3.9 4.64 5.32 6.9

$Petal.Width
  [1] 0.2  0.2  0.2  0.2  0.2  1.16 1.16 0.2  0.2  0.2  0.2  0.2  0.2  0.2  0.2 
 [16] 1.16 1.16 1.16 1.16 1.16 0.2  1.16 0.2  1.16 0.2  0.2  1.16 0.2  0.2  0.2 
 [31] 0.2  1.16 0.2  0.2  0.2  0.2  0.2  0.2  0.2  0.2  1.16 1.16 0.2  1.16 1.16
 [46] 1.16 0.2  0.2  0.2  0.2  1.5  1.5  1.5  1.5  1.5  1.5  1.9  1.16 1.5  1.5 
 [61] 1.16 1.5  1.16 1.5  1.5  1.5  1.5  1.16 1.5  1.16 1.9  1.5  1.5  1.5  1.5 
 [76] 1.5  1.5  1.9  1.5  1.16 1.16 1.16 1.5  1.9  1.5  1.9  1.5  1.5  1.5  1.5 
 [91] 1.5  1.5  1.5  1.16 1.5  1.5  1.5  1.5  1.16 1.5  2.5  1.9  2.5  1.9  2.5 
[106] 2.5  1.9  1.9  1.9  2.5  2.5  1.9  2.5  2.5  2.5  2.5  1.9  2.5  2.5  1.5 
[121] 2.5  2.5  2.5  1.9  2.5  1.9  1.9  1.9  2.5  1.9  1.9  2.5  2.5  1.5  1.5 
[136] 2.5  2.5  1.9  1.9  2.5  2.5  2.5  1.9  2.5  2.5  2.5  1.9  2.5  2.5  1.9 
Levels: 0.2 1.16 1.5 1.9 2.5

$Species
  [1] setosa     setosa     setosa     setosa     setosa     setosa    
  [7] setosa     setosa     setosa     setosa     setosa     setosa    
 [13] setosa     setosa     setosa     setosa     setosa     setosa    
 [19] setosa     setosa     setosa     setosa     setosa     setosa    
 [25] setosa     setosa     setosa     setosa     setosa     setosa    
 [31] setosa     setosa     setosa     setosa     setosa     setosa    
 [37] setosa     setosa     setosa     setosa     setosa     setosa    
 [43] setosa     setosa     setosa     setosa     setosa     setosa    
 [49] setosa     setosa     versicolor versicolor versicolor versicolor
 [55] versicolor versicolor versicolor versicolor versicolor versicolor
 [61] versicolor versicolor versicolor versicolor versicolor versicolor
 [67] versicolor versicolor versicolor versicolor versicolor versicolor
 [73] versicolor versicolor versicolor versicolor versicolor versicolor
 [79] versicolor versicolor versicolor versicolor versicolor versicolor
 [85] versicolor versicolor versicolor versicolor versicolor versicolor
 [91] versicolor versicolor versicolor versicolor versicolor versicolor
 [97] versicolor versicolor versicolor versicolor virginica  virginica 
[103] virginica  virginica  virginica  virginica  virginica  virginica 
[109] virginica  virginica  virginica  virginica  virginica  virginica 
[115] virginica  virginica  virginica  virginica  virginica  virginica 
[121] virginica  virginica  virginica  virginica  virginica  virginica 
[127] virginica  virginica  virginica  virginica  virginica  virginica 
[133] virginica  virginica  virginica  virginica  virginica  virginica 
[139] virginica  virginica  virginica  virginica  virginica  virginica 
[145] virginica  virginica  virginica  virginica  virginica  virginica 
Levels: setosa versicolor virginica

attr(,"class")
[1] "inum"
  [1]  5  1  3  2  6 24 16  3  1  2  7 11  1  1  8 20 19 19 25 19 12 19  6 22 11
 [26]  9 21  7  4 11 10 17  7  7  2  3  7  6  1  4 18 14  3 23 24 15 13  3  7  3
 [51] 46 41 45 33 38 37 51 26 39 30 26 37 29 43 32 40 36 29 35 27 50 37 42 43 38
 [76] 39 44 49 37 28 27 27 31 48 36 47 45 35 36 33 33 37 34 26 33 37 37 38 27 37
[101] 76 56 74 61 73 74 55 62 60 78 71 57 74 65 67 71 61 78 72 52 77 66 74 57 77
[126] 64 59 58 73 62 62 78 73 53 54 74 76 63 58 75 75 70 56 77 77 69 57 68 76 58
attr(,"levels")
   Sepal.Length Sepal.Width Petal.Length Petal.Width    Species (weights)
1          5.00         3.0         1.50        0.20     setosa         5
2          5.00         3.1         1.50        0.20     setosa         3
3          5.00         3.4         1.50        0.20     setosa         6
4          5.60         3.4         1.50        0.20     setosa         2
5            NA         4.4         1.50        0.20     setosa         1
6          5.00         4.4         1.50        0.20     setosa         3
7          5.60         4.4         1.50        0.20     setosa         6
8          6.10         4.4         1.50        0.20     setosa         1
9          5.00         3.0         3.90        0.20     setosa         1
10         5.00         3.1         3.90        0.20     setosa         1
11         5.00         3.4         3.90        0.20     setosa         3
12         5.60         3.4         3.90        0.20     setosa         1
13         5.60         4.4         3.90        0.20     setosa         1
14         5.00         2.7         1.50        1.16     setosa         1
15         5.00         3.0         1.50        1.16     setosa         1
16         5.00         3.4         1.50        1.16     setosa         1
17         5.60         3.4         1.50        1.16     setosa         1
18         5.00         4.4         1.50        1.16     setosa         1
19         5.60         4.4         1.50        1.16     setosa         4
20         6.10         4.4         1.50        1.16     setosa         1
21         5.00         3.4         3.90        1.16     setosa         1
22         5.60         3.4         3.90        1.16     setosa         1
23         5.00         4.4         3.90        1.16     setosa         1
24         5.60         4.4         3.90        1.16     setosa         2
25         6.10         4.4         3.90        1.16     setosa         1
26         5.00         2.7         3.90        1.16 versicolor         3
27         5.60         2.7         3.90        1.16 versicolor         4
28         6.10         2.7         3.90        1.16 versicolor         1
29         6.10         2.7         4.64        1.16 versicolor         2
30         5.60         2.7         3.90        1.50 versicolor         1
31         6.10         2.7         3.90        1.50 versicolor         1
32         5.60         3.0         3.90        1.50 versicolor         1
33         5.60         2.7         4.64        1.50 versicolor         4
34         6.10         2.7         4.64        1.50 versicolor         1
35         6.54         2.7         4.64        1.50 versicolor         2
36         5.60         3.0         4.64        1.50 versicolor         3
37         6.10         3.0         4.64        1.50 versicolor         8
38         6.54         3.0         4.64        1.50 versicolor         3
39         7.90         3.0         4.64        1.50 versicolor         2
40         7.90         3.1         4.64        1.50 versicolor         1
41         6.54         3.4         4.64        1.50 versicolor         1
42         6.54         2.7         5.32        1.50 versicolor         1
43         6.10         3.0         5.32        1.50 versicolor         2
44         7.90         3.0         5.32        1.50 versicolor         1
45         7.90         3.1         5.32        1.50 versicolor         2
46         7.90         3.4         5.32        1.50 versicolor         1
47         6.10         3.4         4.64        1.90 versicolor         1
48         6.10         2.7         5.32        1.90 versicolor         1
49         7.90         3.0         5.32        1.90 versicolor         1
50         6.10         3.4         5.32        1.90 versicolor         1
51         6.54         3.4         5.32        1.90 versicolor         1
52         6.10         2.7         5.32        1.50  virginica         1
53         6.54         3.0         5.32        1.50  virginica         1
54         6.10         2.7         6.90        1.50  virginica         1
55         5.00         2.7         4.64        1.90  virginica         1
56         6.10         2.7         5.32        1.90  virginica         2
57         6.54         2.7         5.32        1.90  virginica         3
58         6.10         3.0         5.32        1.90  virginica         3
59         6.54         3.0         5.32        1.90  virginica         1
60         7.90         2.7         6.90        1.90  virginica         1
61         6.54         3.0         6.90        1.90  virginica         2
62         7.90         3.0         6.90        1.90  virginica         3
63         6.54         3.1         6.90        1.90  virginica         1
64         7.90         3.4         6.90        1.90  virginica         1
65         6.10         2.7         5.32        2.50  virginica         1
66         5.60         3.0         5.32        2.50  virginica         1
67         6.10         3.0         5.32        2.50  virginica         1
68         6.54         3.0         5.32        2.50  virginica         1
69         7.90         3.0         5.32        2.50  virginica         1
70         7.90         3.1         5.32        2.50  virginica         1
71         6.54         3.4         5.32        2.50  virginica         2
72         7.90         2.7         6.90        2.50  virginica         1
73         6.54         3.0         6.90        2.50  virginica         3
74         7.90         3.0         6.90        2.50  virginica         5
75         7.90         3.1         6.90        2.50  virginica         2
76         6.54         3.4         6.90        2.50  virginica         3
77         7.90         3.4         6.90        2.50  virginica         4
78         7.90         4.4         6.90        2.50  virginica         3
attr(,"class")
[1] "inumtotal"
  [1]  5  1  3  2  0 24 16  3  1  2  7 11  1  1  8 20 19 19 25 19 12 19  6 22 11
 [26]  9 21  7  4 11 10 17  7  7  2  3  7  6  1  4 18 14  3 23 24 15 13  3  7  3
 [51] 45 40 44 32 37 36 50 26 38 30 26 36 29 42 31 39 35 29 34 27 49 36 41 42 37
 [76] 38 43 48 36 28 27 27  0 47 35 46 44 34 35 32 32 36 33 26 32 36 36 37 27 36
[101] 75 55 73 60 72 73 54 61 59 77 70 56 73 64 66 70 60 77 71 51 76 65 73 56 76
[126] 63 58 57 72 61 61 77 72 52 53 73 75 62 57 74 74 69 55 76 76 68 56 67 75 57
attr(,"levels")
   Sepal.Length Sepal.Width Petal.Length Petal.Width    Species (weights)
1          5.00     (2.7,3]         1.50        0.20     setosa         5
2          5.00     (3,3.1]         1.50        0.20     setosa         3
3          5.00   (3.1,3.4]         1.50        0.20     setosa         6
4          5.60   (3.1,3.4]         1.50        0.20     setosa         2
6          5.00   (3.4,4.4]         1.50        0.20     setosa         3
7          5.60   (3.4,4.4]         1.50        0.20     setosa         6
8          6.10   (3.4,4.4]         1.50        0.20     setosa         1
9          5.00     (2.7,3]         3.90        0.20     setosa         1
10         5.00     (3,3.1]         3.90        0.20     setosa         1
11         5.00   (3.1,3.4]         3.90        0.20     setosa         3
12         5.60   (3.1,3.4]         3.90        0.20     setosa         1
13         5.60   (3.4,4.4]         3.90        0.20     setosa         1
14         5.00   (1.9,2.7]         1.50        1.16     setosa         1
15         5.00     (2.7,3]         1.50        1.16     setosa         1
16         5.00   (3.1,3.4]         1.50        1.16     setosa         1
17         5.60   (3.1,3.4]         1.50        1.16     setosa         1
18         5.00   (3.4,4.4]         1.50        1.16     setosa         1
19         5.60   (3.4,4.4]         1.50        1.16     setosa         4
20         6.10   (3.4,4.4]         1.50        1.16     setosa         1
21         5.00   (3.1,3.4]         3.90        1.16     setosa         1
22         5.60   (3.1,3.4]         3.90        1.16     setosa         1
23         5.00   (3.4,4.4]         3.90        1.16     setosa         1
24         5.60   (3.4,4.4]         3.90        1.16     setosa         2
25         6.10   (3.4,4.4]         3.90        1.16     setosa         1
26         5.00   (1.9,2.7]         3.90        1.16 versicolor         3
27         5.60   (1.9,2.7]         3.90        1.16 versicolor         4
28         6.10   (1.9,2.7]         3.90        1.16 versicolor         1
29         6.10   (1.9,2.7]         4.64        1.16 versicolor         2
30         5.60   (1.9,2.7]         3.90        1.50 versicolor         1
31         6.10   (1.9,2.7]         3.90        1.50 versicolor         1
32         5.60     (2.7,3]         3.90        1.50 versicolor         1
33         5.60   (1.9,2.7]         4.64        1.50 versicolor         4
34         6.10   (1.9,2.7]         4.64        1.50 versicolor         1
35         6.54   (1.9,2.7]         4.64        1.50 versicolor         2
36         5.60     (2.7,3]         4.64        1.50 versicolor         3
37         6.10     (2.7,3]         4.64        1.50 versicolor         8
38         6.54     (2.7,3]         4.64        1.50 versicolor         3
39         7.90     (2.7,3]         4.64        1.50 versicolor         2
40         7.90     (3,3.1]         4.64        1.50 versicolor         1
41         6.54   (3.1,3.4]         4.64        1.50 versicolor         1
42         6.54   (1.9,2.7]         5.32        1.50 versicolor         1
43         6.10     (2.7,3]         5.32        1.50 versicolor         2
44         7.90     (2.7,3]         5.32        1.50 versicolor         1
45         7.90     (3,3.1]         5.32        1.50 versicolor         2
46         7.90   (3.1,3.4]         5.32        1.50 versicolor         1
47         6.10   (3.1,3.4]         4.64        1.90 versicolor         1
48         6.10   (1.9,2.7]         5.32        1.90 versicolor         1
49         7.90     (2.7,3]         5.32        1.90 versicolor         1
50         6.10   (3.1,3.4]         5.32        1.90 versicolor         1
51         6.54   (3.1,3.4]         5.32        1.90 versicolor         1
52         6.10   (1.9,2.7]         5.32        1.50  virginica         1
53         6.54     (2.7,3]         5.32        1.50  virginica         1
54         6.10   (1.9,2.7]         6.90        1.50  virginica         1
55         5.00   (1.9,2.7]         4.64        1.90  virginica         1
56         6.10   (1.9,2.7]         5.32        1.90  virginica         2
57         6.54   (1.9,2.7]         5.32        1.90  virginica         3
58         6.10     (2.7,3]         5.32        1.90  virginica         3
59         6.54     (2.7,3]         5.32        1.90  virginica         1
60         7.90   (1.9,2.7]         6.90        1.90  virginica         1
61         6.54     (2.7,3]         6.90        1.90  virginica         2
62         7.90     (2.7,3]         6.90        1.90  virginica         3
63         6.54     (3,3.1]         6.90        1.90  virginica         1
64         7.90   (3.1,3.4]         6.90        1.90  virginica         1
65         6.10   (1.9,2.7]         5.32        2.50  virginica         1
66         5.60     (2.7,3]         5.32        2.50  virginica         1
67         6.10     (2.7,3]         5.32        2.50  virginica         1
68         6.54     (2.7,3]         5.32        2.50  virginica         1
69         7.90     (2.7,3]         5.32        2.50  virginica         1
70         7.90     (3,3.1]         5.32        2.50  virginica         1
71         6.54   (3.1,3.4]         5.32        2.50  virginica         2
72         7.90   (1.9,2.7]         6.90        2.50  virginica         1
73         6.54     (2.7,3]         6.90        2.50  virginica         3
74         7.90     (2.7,3]         6.90        2.50  virginica         5
75         7.90     (3,3.1]         6.90        2.50  virginica         2
76         6.54   (3.1,3.4]         6.90        2.50  virginica         3
77         7.90   (3.1,3.4]         6.90        2.50  virginica         4
78         7.90   (3.4,4.4]         6.90        2.50  virginica         3
attr(,"class")
[1] "inumtotal"

inum documentation built on Dec. 12, 2017, 3:01 p.m.

Related to inum in inum...