【发布时间】:2016-07-23 07:42:17
【问题描述】:
您好,我一直在尝试将我的数据重新调整为更宽。
id story_id
1 123
1 123
1 123
1 123
2 213
2 213
2 213
3 123
3 123
3 123
但我得到的只是:
id
1
2
3
我正在使用代码:
data=reshape(data, idvar="id", timevar="story_id", direction="wide")
想要的输出是
id story_id.123 story_id.213
1 123 NA
2 NA 213
3 123 NA
请告诉我问题出在哪里。
【问题讨论】:
-
我已经更新了我的问题@MrFlick
-
table(unique(data))不是更可取吗?reshape(unique(data)[, c(1,2,2)], timevar = 'story_id.1', v.names = 'story_id', dir = 'wide')也可以使用 -
@rawr - 你甚至可以压扁一点
reshape(transform(unique(data), time=story_id), idvar="id", direction="wide")
标签: r reshape data-manipulation