【发布时间】:2015-06-12 10:21:28
【问题描述】:
我有一个列格式类似于此的 CSV:
Section | ID | Totaltime | Item1/Word | Item1/Cat | Item1/Time...Item235/Time
我想重新调整它,以便每个 ID 的所有 235 个条目都不是在一行上,而是每个项目有一行,按 ID 排序/分块,所以它看起来类似于这个-
Section | ID0 | Totaltime | Item1/Word | Item1/Cat | Item1/Time
Item2/Word | Item2/Cat | Item2/Time
Item3/Word | Item3/Cat | Item3/Time
...Item235/Word | Item235/Cat | Item235/Time
Section | ID1 | Totaltime | Item1/Word | Item1/Cat | Item1/Time...
我尝试使用 ID 作为 vars.id 参数来融合它,并将各种项目通过 grepl 拉到 measure.vars 参数中,但这会导致类似这样的结果-
Section | ID0 | Totaltime
Section | ID0 | Item1/Word
Section | ID0 | Item1/Cat
Section | ID0 | Item1/Time
...
Section | ID0 | Item235/Word
Section | ID0 | Item235/Cat
Section | ID0 | Item235/Time
我也尝试过重铸这个,但运气不佳。
本周我是 R 新手,所以我确信我可能遗漏了一些非常明显的东西,但我在这方面遇到了困难。
【问题讨论】:
-
您确定要这样做吗?似乎以您想要的格式工作可能会更难。
-
这不是我的数据。这就是他们要求的方式。采用这种特殊格式,长而不是宽。
-
我会回到客户那里,询问他们为什么希望以这种指定的格式拥有它并列举这样做的问题。正如@RichardScriven 指出的那样,它看起来很笨拙。