我一直在研究这两天,但仍然找不到答案。这是我的问题:
我有一组由一个函数创建的数据,用于自动从源中提取一些数据。它看起来像这样:
data
Week starting Position Title
2013-01-05 1 HAPPY
2013-01-05 2 SKYSCRAPER
2013-01-05 3 HEY BROTHER
2013-01-05 4 TRUMPETS
2013-01-05 5 THE MONSTER
2013-01-05 6 SOMEWHERE ONLY WE KNOW
2013-01-12 1 HAPPY
2013-01-12 2 SKYSCRAPER
2013-01-12 3 HEY BROTHER
2013-01-12 4 TRUMPETS
2013-01-12 5 THE MONSTER
2013-01-12 6 SOMEWHERE ONLY WE KNOW
... ... ...
我想像这样转置数据,以便我可以运行一些时间序列分析:
Week starting HAPPY SKYSCRAPER HEY BROTHER TRUMPETS THE MONSTER SOMEWHERE ONLY WE KNOW
2013-01-05 1 2 3 4 5 6
2013-01-12 1 2 3 4 5 6
... ... ... ... ... ... ...
这是我可以想到的分析此数据集的一种方法。请随意提出任何其他方式。提前致谢!
答案 0 :(得分:0)
您可能需要查看?reshape
例如:
reshape(data, v.names="Position", timevar="Title", idvar="Week.starting",
direction="wide")