我有一个df如下
structure(list(ProductAccountNumber = c(17397841L, 17397841L,
17397841L, 17397841L, 17397841L, 17397841L, 17397841L, 17397841L,
17397841L, 17397841L, 17397841L, 17397841L, 17397841L, 17397841L,
17397841L, 17397841L, 17397841L, 17397841L, 17397841L, 17397841L,
17397841L, 17397841L, 17397841L, 17397841L, 17397841L, 17397841L,
17397841L, 17397841L, 17397841L, 17397841L, 17397841L, 17397841L,
17397841L), OriginalDate = c("2009-04-14", "2009-04-14", "2009-04-14",
"2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14",
"2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14",
"2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14",
"2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14",
"2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14",
"2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14", "2009-04-14"
), OriginalFICO = c(810L, 810L, 810L, 810L, 810L, 810L, 810L,
810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L,
810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L, 810L,
810L, 810L, 810L, 810L), RefreshFICODate = structure(c(1350273600,
1373860800, 1428292800, 1439524800, 1444363200, 1462939200, 1468900800,
1476676800, 1487653200, 1493265600, 1515646800, 1517893200, 1524024000,
1531800000, 1541131200, 1550034000, 1555300800, 1568088000, 1575435600,
1579669200, 1587441600, 1595563200, 1604293200, 1611723600, 1618459200,
1626926400, 1634961600, 1642050000, 1650859200, 1657944000, 1666584000,
1674018000, 1681272000), class = c("POSIXct", "POSIXt"), tzone = ""),
RefreshFICO = c(831L, 767L, 809L, 827L, 838L, 827L, 829L,
829L, 829L, 840L, 829L, 836L, 848L, 827L, 836L, 836L, 848L,
813L, 848L, 824L, 818L, 818L, 840L, 857L, 805L, 826L, 826L,
832L, 826L, 826L, 826L, 899L, 864L), RefreshFICODate2 = structure(c(1341460800,
1365739200, 1373860800, 1428292800, 1439524800, 1444363200,
1462939200, 1468900800, 1476676800, 1487653200, 1493265600,
1515646800, 1517893200, 1524024000, 1531800000, 1541131200,
1550034000, 1555300800, 1568088000, 1575435600, 1579669200,
1587441600, 1595563200, 1604293200, 1611723600, 1618459200,
1626926400, 1634961600, 1642050000, 1650859200, 1657944000,
1666584000, 1674018000), class = c("POSIXct", "POSIXt"), tzone = ""),
RefreshFICO2 = c(827L, 815L, 767L, 809L, 827L, 838L, 827L,
829L, 829L, 829L, 840L, 829L, 836L, 848L, 827L, 836L, 836L,
848L, 813L, 848L, 824L, 818L, 818L, 840L, 857L, 805L, 826L,
826L, 832L, 826L, 826L, 826L, 899L)), row.names = c(NA, 33L
), class = "data.frame")
我想转换它,使所有的日期从OriginalDate/RefreshFICODateX成为列名和列的值来自OriginalFICO/RefreshFICOX。
| 产品帐号|2009年4月14日|2012-10-15 2012-10-15 2012-10-15| 2012-07-05 2012-07-05|
| - -----|- -----|- -----|- -----|
| 17397841|八一零|八三一|八二七|
我可以一次用一组原始/刷新相当容易地做到这一点,但有10个,必须有一个更简单的方法。是否可以告诉pivot_wider之类的东西在某种意义上“配对”列。
2条答案
按热度按时间nnsrf1az1#
2admgd592#
类似@Onyambu的方法: