【发布时间】:2020-07-29 20:17:51
【问题描述】:
我想将最后一列(在当前数据集中)移动到缺少数据的行(在所需数据集中)。我浏览了 reshape、reshape2 和 tidyr 的软件包。 tidyr 包中的函数gather() 应该是解决方案,但到目前为止我无法处理它。对此有什么建议吗? 提前致谢。
当前数据集:
date citycode cityname cases deaths cases_03_04
1 01-04-2020 1 city1 197 3 241
2 01-04-2020 2 city2 26 0 32
所需数据集:
date citycode cityname cases deaths
1 01-04-2020 1 city1 197 3
2 01-04-2020 2 city2 26 0
3 03-04-2020 1 city1 241 na
4 03-04-2020 2 city2 32 na
【问题讨论】:
-
你本质上想
rbind。但是,日期是怎么来的? -
@NelsonGon 一点也不。 currDataSet的最后一列从cases_03_04分布到desDataSet中的行到cases中。
标签: r dataframe dataset reshape tidyr