【发布时间】:2020-04-17 22:30:42
【问题描述】:
我在下面提供了一些过滤(使用 dplyr)数据,来自一个更大的 .csv 文件。我打算用这个作为我的独立。线性回归模型中的变量,我也想组合这些列并将它们写入 .csv(因为我正在与我的团队分享。)
我之前将这些数据保存为“列表”(因为每个变量的长度不同),但是当我写入 csv 时,我必须将其转换为矩阵,并且数据与预期的不太一样。
这里的问题是每个过滤集都是不同长度之一,因此不同的值 (CountPD) 归因于不同的日期。如何正确地将这些数据中的每一个组合到一个数据框(或类似的东西)中,我可以在其中编写为 csv 并在将来应用线性回归(即 colnames 是“Date”,“y1”,“y2 “……等等)
Y1:
structure(list(Date = structure(c(12083, 12111, 12142, 12172,
12203, 17500, 17531, 17562, 17590, 17621, 17651), class = "Date"),
CountPD = c(1, 1, 1, NA, 1, NA, 0.083, NA, NA, 0.083, 0.083
)), row.names = c(1L, 2L, 3L, 4L, 5L, 179L, 180L, 181L, 182L,
183L, 184L), class = "data.frame")
Y2:
structure(list(Date = structure(c(17013, 17044, 17074, 17105,
17135, NA), class = "Date"), CountPD = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_)), row.names = c("1",
"2", "3", "4", "5", "NA"), class = "data.frame")
Y3:
structure(list(Date = structure(c(12783, 12814, 12842, 12873,
12903, 17500, 17531, 17562, 17590, 17621, 17651), class = "Date"),
CountPD = c(NA, 0.333, NA, NA, NA, NA, 0.125, 0.125, 0.222,
0.2, 0.25)), row.names = c(1L, 2L, 3L, 4L, 5L, 156L, 157L,
158L, 159L, 160L, 161L), class = "data.frame")
Y4:
structure(list(Date = structure(c(12356, 12417, 12448, 12477,
12508, 17500, 17531, 17562, 17590, 17621, 17651), class = "Date"),
CountPD = c(NA, NA, NA, NA, NA, 0.2, 0.2, 0.182, 0.182, 0.222,
0.25)), row.names = c(1L, 2L, 3L, 4L, 5L, 160L, 161L, 162L,
163L, 164L, 165L), class = "data.frame")```
【问题讨论】:
标签: r dataframe sorting linear-regression data-cleaning