user3603831
user3603831

Reputation: 87

Normalize data with R

I have a dataframe called data which contains 5 columns and approximately 181 rows.

I'm trying to run some algorithm on this dataframe, but I have to do some pre-processing beforehand and normalize the columns to have zero and 1. I am using R and the problem that i have columns whit not numeric data like this:

Name       ZwaveType ProprietesName Value                Date
Switcher19         0              2     1 2014-03-01 06:45:00
Switcher5          0              2     1 2014-03-01 07:00:00
Switcher15         0              2     1 2014-03-01 07:15:00
Switcher4          0              2     1 2014-03-01 07:14:30
Switcher15         0              2     0 2014-03-01 07:25:00
Switcher19         0              2     0 2014-03-01 07:45:00

I'd like to ask how can I achieve normalization with R for this case?

Upvotes: 1

Views: 1483

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226911

Probably something like

col.classes <- sapply(mydata,class)
num.cols <- (col.classes=="numeric")
mydata[,num.cols] <- scale(mydata[,num.cols])

Upvotes: 1

Related Questions