In R, standardizing data involves scaling the values in a numerical variable so that they have a zero mean and a standard deviation of one. This is important because some machine learning algorithms assume that the variables are standardized to prevent variables with large values from dominating the results.
There are several ways to standardize data in R. One easy way is to use the scale() function. Here is an example:
main.r172 chars9 lines
This will produce the following output:
main.r96 chars7 lines
Another option is to use the caret package, which provides a preProcess() function that can be used to standardize data. Here is an example:
main.r297 chars12 lines
This will produce the following output:
main.r109 chars8 lines
In this example, the preProcess() function has been used to standardize both variables in the data frame by shifting their values so that they have a mean of zero, and scaling them so that they have a standard deviation of one.
gistlibby LogSnag