Вот мой data_frame
объект:
structure(list(dt = structure(c(17702, 17702, 17702, 17702, 17703,
17703, 17704, 17705, 17705, 17706, 17706, 17706, 17706), class = "Date"),
uuid_lev = c(4L, 5L, 8L, 10L, 6L, 8L, 8L, 1L, 7L, 2L, 3L,
7L, 9L), mean_call_duration = c(57.8043647700702, 222.806,
132.73, 74.976645858206, 204.53, 138.8385, 138.21, 113.478,
162.656, 127.714, 145.507732189148, 168.676, 73.928), median_call_duration = c(29,
78, 25.6666666666667, 29, 36, 23.875, 23.5, 25, 44, 14, 30,
46, 16), max_call_duration = c(2117, 4589, 5137, 4470, 3966,
5137, 5137, 3249, 5137, 7201, 7201, 5137, 1941), min_call_duration = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("dt", "uuid_lev",
"mean_call_duration", "median_call_duration", "max_call_duration",
"min_call_duration"), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -13L), vars = "dt", drop = TRUE, indices = list(
0:3, 4:5, 6L, 7:8, 9:12), group_sizes = c(4L, 2L, 1L, 2L,
4L), biggest_group_size = 4L, labels = structure(list(dt = structure(c(17702,
17703, 17704, 17705, 17706), class = "Date")), class = "data.frame", row.names = c(NA,
-5L), vars = "dt", drop = TRUE, .Names = "dt"))
Вот моя функция масштаба:
scale_0_1 <- function(x) {
return((x - min(x)) /(max(x) - min(x)))
}
Когда я применяю функцию к каждому из следующих столбцов, она работает:
mean_call_duration
<dbl>
median_call_duration
<dbl>
max_call_duration
Но когда я применяю это, используя:
call_logs_call_duration_stats_agg %>%
mutate(mean_call_duration = scale_0_1(mean_call_duration),
median_call_duration = scale_0_1(median_call_duration),
max_call_duration = scale_0_1(max_call_duration))
Я получаю NaN
s:
structure(list(dt = structure(c(17702, 17702, 17702, 17702, 17703,
17703, 17704, 17705, 17705, 17706, 17706, 17706, 17706), class = "Date"),
uuid_lev = c(4L, 5L, 8L, 10L, 6L, 8L, 8L, 1L, 7L, 2L, 3L,
7L, 9L), mean_call_duration = c(0, 1, 0.454090258714836,
0.104073399419383, 1, 0, NaN, 0, 1, 0.567674251699244, 0.755474861623972,
1, 0), median_call_duration = c(0.0636942675159236, 1, 0,
0.0636942675159236, 1, 0, NaN, 0, 1, 0, 0.5, 1, 0.0625),
max_call_duration = c(0, 0.818543046357616, 1, 0.779139072847682,
0, 1, NaN, 0, 1, 1, 1, 0.607604562737643, 0), min_call_duration = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("dt", "uuid_lev",
"mean_call_duration", "median_call_duration", "max_call_duration",
"min_call_duration"), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -13L), vars = "dt", labels = structure(list(
dt = structure(c(17702, 17703, 17704, 17705, 17706), class = "Date")), class = "data.frame", row.names = c(NA,
-5L), vars = "dt", drop = TRUE, .Names = "dt"), indices = list(
0:3, 4:5, 6L, 7:8, 9:12), drop = TRUE, group_sizes = c(4L,
2L, 1L, 2L, 4L), biggest_group_size = 4L)
Посоветуйте, пожалуйста, что не так с mutate
?