如果已经问过这个问题,请提前道歉,但是我试图将Date行操纵为一列,并以特定方式汇总结果。
当前结果:月结帐户ID GroupID是数据集的标题
MonthEnd AccountID GroupID
31/05/2019 ID 1 Group1
31/05/2019 ID 2 Group2
31/05/2019 ID 3 Group3
31/05/2019 ID 4 Group4
我想得到的是,groupID按月汇总,每一行代表一个AccountID-
MonthEnd 31/05/2019 30/04/2019 30/03/2019 30/02/2019
ID 1 Group1 Group1 Group1 Group1
ID 2 Group2 Group2 Group2 Group2
ID 3 Group3 Group3 Group3 Group3
ID 4 Group4 Group4 Group4 Group4
我尝试在Excel中进行透视,但“值”列不允许仅字母或单词编号的值
我尝试使用
Dcast(DataColFileV2, DataColFileV2$MonthEnd,
DataColFileV2$AccountID, DataColFileV2$GroupID)
然后我收到错误消息“不知道如何解析”。
我从跑步中得到的结果
dput(head(DataColFileV2))
structure(list(MonthEnd = structure(c(1559260800, 1559260800,
1559260800, 1559260800, 1559260800, 1559260800), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), AccountID = c("ID1",
"ID2", "ID3", "ID4"), groupID = c("Group1", "Group2", "Group3",
"Group4")), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
我尝试使用
dcast(DataColFileV2,AccountID~MonthEnd, values="GroupID")
AccountID 2017-05-31 2017-06-30 2017-07-31 2017-08-31 2017-09-30 2017-10-31 2017-11-30 2017-12-31 2018-01-31
1 000054-000001 0 0 0 0 1 0 0 0 0
2 000063-000006 0 0 0 0 0 0 0 0 0
3 000063-000007 0 0 0 0 0 0 0 0 0
4 000063-000011 0 0 0 0 0 0 0 0 0
5 000064-000001 0 0 0 0 0 0 0 0 0
6 000064-000005 0 0 0 0 0 0 0 0 1
reshape(DataColFileV2,idvar = "AccountID",MonthEnd = "MonthEnd", direction = "wide")
"AccountID" `"GroupID"c(1559260800, 1556582400, 1553990400, 1551312000, 1548892800, 1546214400, 1543536000, 154~
<chr> <chr>
1 002246-000055 NA
2 009001-000001 NA
3 003117-000355 NA
4 006853-000126 NA
5 002171-000068 NA
6 003013-007855 NA
7 001762-000462 NA
8 006853-000102 NA
9 006980-000057 NA
10 005980-000150 NA
dcast是我追求的最接近的结果,但是组ID而不是数字,而不是实际字符串,例如Group1,Group2等