简体   繁体   English

用R归一化数据

[英]Normalize data with R

I have a dataframe called data which contains 5 columns and approximately 181 rows. 我有一个名为data的数据框,其中包含5列和大约181行。

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: 我正在尝试在此数据帧上运行某种算法,但是我必须事先进行一些预处理,并将列归一化为零和1。我正在使用R,还有这样的问题,我的列没有像这样的数字数据:

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? 我想问一下如何在这种情况下用R实现归一化?

Probably something like 大概像

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM