规范化应用于数据帧的数据的功能错误

时间:2017-09-13 00:03:09

标签: r function normalization

我从UCI机器学习库下载了自行车共享数据集,并尝试在R中实现多元线性回归。以下是数据的格式:

> head(data1)
  season mnth hr holiday weekday workingday weathersit temp  atemp  hum windspeed cnt
1      1    1  0       0       6          0          1 0.24 0.2879 0.81    0.0000  16
2      1    1  1       0       6          0          1 0.22 0.2727 0.80    0.0000  40
3      1    1  2       0       6          0          1 0.22 0.2727 0.80    0.0000  32
4      1    1  3       0       6          0          1 0.24 0.2879 0.75    0.0000  13
5      1    1  4       0       6          0          1 0.24 0.2879 0.75    0.0000   1
6      1    1  5       0       6          0          2 0.24 0.2576 0.75    0.0896   1

我正在尝试使用以下函数规范化特定列(尚未规范化):

normalize <- function(x) {
  return ((x - min(x)) / (max(x) - min(x)))
}

问题是我跑的时候:

 dfNorm <- as.data.frame(lapply(data1["season", "mnth", "hr", "weekday", "weathersit"], normalize)) 

我收到以下错误:

  

[.data.frame中的错误(数据1,&#34;季节&#34;,&#34;月&#34;,&#34;小时&#34;,&#34;工作日&#34;,   &#34; weathersit&#34;):未使用的参数(&#34;工作日&#34;,&#34; weathersit&#34;)

为什么我会收到此错误以及如何解决?

2 个答案:

答案 0 :(得分:1)

要就地修改,我会使用angleMode(DEGREES); for (let i = 0; i <= 60; i++) { //translate(width / 2, height / 2); rotate(6); rect(centerW + 500, centerH, 100, 50); } 。这样的事情应该有效:

dplyr::mutate

答案 1 :(得分:1)

只需将lapply分配给新列:

df[c("season_norm", "mnth_norm", "hr_norm", "weekday_norm", "weathersit_norm")] <-
   lapply(df[c("season", "mnth", "hr", "weekday", "weathersit")], normalize)