【发布时间】:2019-04-17 03:46:28
【问题描述】:
我正在尝试组织我的数据集以进行后续分析(趋势分析、绘图等)。数据采用列表的形式,我想将其转换为数据框。
我的完整数据集将包含大约 300 口井和 40 年的数据。每口井都有不同的记录长度,即一些井将有 40 年的记录,有些将有 5 年。对于这个例子,我只使用了两口井和 1 年的数据。
从其他帖子中,我设法将动物园对象合并在一起,为每个井创建一个列。但是,我希望这些列也包含站点名称。
我确实注意到日期/时间似乎不在它自己的列中;我不确定这是否会在以后出现问题。同样值得关注的是我将通过将所有日期/时间值合并在一起生成的日期/时间值的数量。我想知道是否有比我计划的更好的方法。
dput(z)
list(structure(c(-3.221, -3.601, -3.321, -2.861, -2.661, -2.491,
-2.297, -2.373, -2.348, -2.216, -2.569, -2.676), SiteName = "Well..3737 7D Flaxmere", Measurement = "Depth From Land Surface", Units = "m", InterpolationMethod = "Quasi-continuous", DataType = "SimpleTimeSeries", TSType = "StdSeries", class = "zoo", index = structure(c(1515061200L,
1517484600L, 1519901100L, 1522761900L, 1525177200L, 1528199400L,
1530619800L, 1533209100L, 1535978400L, 1538994000L, 1541071500L,
1544693700L), class = c("POSIXct", "POSIXt"), tzone = "UTC")),
structure(c(4.30654362318781, 3.08465060629183, 3.69719825206464,
4.22951094416319, 4.74166852727183, 5.25868509480613, 5.37266948414152,
5.24168682648358, 5.09669530682964, 4.71066298287734, 5.05269565318106,
4.74566920516198), SiteName = "Well...222 Comminutor Stn", Measurement = "Depth From Land Surface", Units = "m", InterpolationMethod = "Quasi-continuous", DataType = "SimpleTimeSeries", TSType = "StdSeries", class = "zoo", index = structure(c(1515139200L,
1517491200L, 1519898400L, 1522762800L, 1525179600L, 1528186800L,
1530528900L, 1533199500L, 1535962200L, 1539082200L, 1541160300L,
1544786400L), class = c("POSIXct", "POSIXt"), tzone = "UTC")))
这是我迄今为止尝试过的,它接近工作了 - 除了我没有列名
test1 <- data.frame(setNames(do.call(cbind, unname(z)), names(z)))
我希望输出看起来像这样。
head(test1)
Date/Time Well...222 Comminutor Stn Well..3737 7D Flaxmere
2018-01-04 10:20:00 -3.221 NA
2018-01-05 08:00:00 NA 4.306544
2018-02-01 11:30:00 -3.601 NA
2018-02-01 13:20:00 NA 3.084651
2018-03-01 10:00:00 NA 3.697198
2018-03-01 10:45:00 -3.321 NA
但目前看起来是这样的
X1 X2
2018-01-04 10:20:00 -3.221 NA
2018-01-05 08:00:00 NA 4.306544
2018-02-01 11:30:00 -3.601 NA
2018-02-01 13:20:00 NA 3.084651
2018-03-01 10:00:00 NA 3.697198
2018-03-01 10:45:00 -3.321 NA
【问题讨论】:
标签: r list dataframe time-series zoo