standardize: Standardize Variables

Description Usage Arguments Details Value Examples

Description

This function takes in a dataframe, the name of any number of variables. It then returns either a vector or a dataframe of scaling results. If passed a single variable name, standardize will return a the standardized variable as a vector, when passed 2 or more variable names, standardize will return a data frame containing all of the standardized variables.

Usage

1
standardize(data, variable, type = "absolute")

Arguments

data

data.frame object that contains both the dependent variable and predictor variables you want to regress.

variable

variable name or vector of names for variables you want standardized.

type

by default, 'absolute' will scale every variable from 0 to 1. "classic" is a little more complicated where the variable is rescaled the mean equaling 0 and a standard deviation is 1.

Details

Often times we are forced to compare variables which exist on different scales, but how do you compare the coefficient for a country's population to one that's much smaller? Standardizing your variables can make reading regression results more useful because it will make coeficients more comparable.

Value

if the function is passed a single variable to standardize, it will return a vector of all obeservations in the variable standardized. If the function is passed more than one variable name, it will return a data-frame containing the new observation values.

Examples

1
2
3
exam.df <- iris
standardize(exam.df, "Petal.Width")
standardize(exam.df, c("Petal.Width", "Petal.Length"), type = "classic")

Example output

  [1] 0.04166667 0.04166667 0.04166667 0.04166667 0.04166667 0.12500000
  [7] 0.08333333 0.04166667 0.04166667 0.00000000 0.04166667 0.04166667
 [13] 0.00000000 0.00000000 0.04166667 0.12500000 0.12500000 0.08333333
 [19] 0.08333333 0.08333333 0.04166667 0.12500000 0.04166667 0.16666667
 [25] 0.04166667 0.04166667 0.12500000 0.04166667 0.04166667 0.04166667
 [31] 0.04166667 0.12500000 0.00000000 0.04166667 0.04166667 0.04166667
 [37] 0.04166667 0.00000000 0.04166667 0.04166667 0.08333333 0.08333333
 [43] 0.04166667 0.20833333 0.12500000 0.08333333 0.04166667 0.04166667
 [49] 0.04166667 0.04166667 0.54166667 0.58333333 0.58333333 0.50000000
 [55] 0.58333333 0.50000000 0.62500000 0.37500000 0.50000000 0.54166667
 [61] 0.37500000 0.58333333 0.37500000 0.54166667 0.50000000 0.54166667
 [67] 0.58333333 0.37500000 0.58333333 0.41666667 0.70833333 0.50000000
 [73] 0.58333333 0.45833333 0.50000000 0.54166667 0.54166667 0.66666667
 [79] 0.58333333 0.37500000 0.41666667 0.37500000 0.45833333 0.62500000
 [85] 0.58333333 0.62500000 0.58333333 0.50000000 0.50000000 0.50000000
 [91] 0.45833333 0.54166667 0.45833333 0.37500000 0.50000000 0.45833333
 [97] 0.50000000 0.50000000 0.41666667 0.50000000 1.00000000 0.75000000
[103] 0.83333333 0.70833333 0.87500000 0.83333333 0.66666667 0.70833333
[109] 0.70833333 1.00000000 0.79166667 0.75000000 0.83333333 0.79166667
[115] 0.95833333 0.91666667 0.70833333 0.87500000 0.91666667 0.58333333
[121] 0.91666667 0.79166667 0.79166667 0.70833333 0.83333333 0.70833333
[127] 0.70833333 0.70833333 0.83333333 0.62500000 0.75000000 0.79166667
[133] 0.87500000 0.58333333 0.54166667 0.91666667 0.95833333 0.70833333
[139] 0.70833333 0.83333333 0.95833333 0.91666667 0.75000000 0.91666667
[145] 1.00000000 0.91666667 0.75000000 0.79166667 0.91666667 0.70833333
    stand.Petal.Width stand.Petal.Length
1       -1.3110521482        -1.33575163
2       -1.3110521482        -1.33575163
3       -1.3110521482        -1.39239929
4       -1.3110521482        -1.27910398
5       -1.3110521482        -1.33575163
6       -1.0486667950        -1.16580868
7       -1.1798594716        -1.33575163
8       -1.3110521482        -1.27910398
9       -1.3110521482        -1.33575163
10      -1.4422448248        -1.27910398
11      -1.3110521482        -1.27910398
12      -1.3110521482        -1.22245633
13      -1.4422448248        -1.33575163
14      -1.4422448248        -1.50569459
15      -1.3110521482        -1.44904694
16      -1.0486667950        -1.27910398
17      -1.0486667950        -1.39239929
18      -1.1798594716        -1.33575163
19      -1.1798594716        -1.16580868
20      -1.1798594716        -1.27910398
21      -1.3110521482        -1.16580868
22      -1.0486667950        -1.27910398
23      -1.3110521482        -1.56234224
24      -0.9174741184        -1.16580868
25      -1.3110521482        -1.05251337
26      -1.3110521482        -1.22245633
27      -1.0486667950        -1.22245633
28      -1.3110521482        -1.27910398
29      -1.3110521482        -1.33575163
30      -1.3110521482        -1.22245633
31      -1.3110521482        -1.22245633
32      -1.0486667950        -1.27910398
33      -1.4422448248        -1.27910398
34      -1.3110521482        -1.33575163
35      -1.3110521482        -1.27910398
36      -1.3110521482        -1.44904694
37      -1.3110521482        -1.39239929
38      -1.4422448248        -1.33575163
39      -1.3110521482        -1.39239929
40      -1.3110521482        -1.27910398
41      -1.1798594716        -1.39239929
42      -1.1798594716        -1.39239929
43      -1.3110521482        -1.39239929
44      -0.7862814418        -1.22245633
45      -1.0486667950        -1.05251337
46      -1.1798594716        -1.33575163
47      -1.3110521482        -1.22245633
48      -1.3110521482        -1.33575163
49      -1.3110521482        -1.27910398
50      -1.3110521482        -1.33575163
51       0.2632599711         0.53362088
52       0.3944526477         0.42032558
53       0.3944526477         0.64691619
54       0.1320672944         0.13708732
55       0.3944526477         0.47697323
56       0.1320672944         0.42032558
57       0.5256453243         0.53362088
58      -0.2615107354        -0.25944625
59       0.1320672944         0.47697323
60       0.2632599711         0.08043967
61      -0.2615107354        -0.14615094
62       0.3944526477         0.25038262
63      -0.2615107354         0.13708732
64       0.2632599711         0.53362088
65       0.1320672944        -0.08950329
66       0.2632599711         0.36367793
67       0.3944526477         0.42032558
68      -0.2615107354         0.19373497
69       0.3944526477         0.42032558
70      -0.1303180588         0.08043967
71       0.7880306775         0.59026853
72       0.1320672944         0.13708732
73       0.3944526477         0.64691619
74       0.0008746178         0.53362088
75       0.1320672944         0.30703027
76       0.2632599711         0.36367793
77       0.2632599711         0.59026853
78       0.6568380009         0.70356384
79       0.3944526477         0.42032558
80      -0.2615107354        -0.14615094
81      -0.1303180588         0.02379201
82      -0.2615107354        -0.03285564
83       0.0008746178         0.08043967
84       0.5256453243         0.76021149
85       0.3944526477         0.42032558
86       0.5256453243         0.42032558
87       0.3944526477         0.53362088
88       0.1320672944         0.36367793
89       0.1320672944         0.19373497
90       0.1320672944         0.13708732
91       0.0008746178         0.36367793
92       0.2632599711         0.47697323
93       0.0008746178         0.13708732
94      -0.2615107354        -0.25944625
95       0.1320672944         0.25038262
96       0.0008746178         0.25038262
97       0.1320672944         0.25038262
98       0.1320672944         0.30703027
99      -0.1303180588        -0.42938920
100      0.1320672944         0.19373497
101      1.7063794137         1.27004036
102      0.9192233541         0.76021149
103      1.1816087073         1.21339271
104      0.7880306775         1.04344975
105      1.3128013839         1.15674505
106      1.1816087073         1.60992627
107      0.6568380009         0.42032558
108      0.7880306775         1.43998331
109      0.7880306775         1.15674505
110      1.7063794137         1.32668801
111      1.0504160307         0.76021149
112      0.9192233541         0.87350679
113      1.1816087073         0.98680210
114      1.0504160307         0.70356384
115      1.5751867371         0.76021149
116      1.4439940605         0.87350679
117      0.7880306775         0.98680210
118      1.3128013839         1.66657392
119      1.4439940605         1.77986923
120      0.3944526477         0.70356384
121      1.4439940605         1.10009740
122      1.0504160307         0.64691619
123      1.0504160307         1.66657392
124      0.7880306775         0.64691619
125      1.1816087073         1.10009740
126      0.7880306775         1.27004036
127      0.7880306775         0.59026853
128      0.7880306775         0.64691619
129      1.1816087073         1.04344975
130      0.5256453243         1.15674505
131      0.9192233541         1.32668801
132      1.0504160307         1.49663097
133      1.3128013839         1.04344975
134      0.3944526477         0.76021149
135      0.2632599711         1.04344975
136      1.4439940605         1.32668801
137      1.5751867371         1.04344975
138      0.7880306775         0.98680210
139      0.7880306775         0.59026853
140      1.1816087073         0.93015445
141      1.5751867371         1.04344975
142      1.4439940605         0.76021149
143      0.9192233541         0.76021149
144      1.4439940605         1.21339271
145      1.7063794137         1.10009740
146      1.4439940605         0.81685914
147      0.9192233541         0.70356384
148      1.0504160307         0.81685914
149      1.4439940605         0.93015445
150      0.7880306775         0.76021149

exploreR documentation built on May 1, 2019, 9:37 p.m.