【发布时间】:2016-02-16 14:06:44
【问题描述】:
我正在学习 R 进行文本挖掘。我有一个 CSV 格式的电视节目表。节目通常从早上 06:00 开始,一直持续到第二天早上 5:00,这被称为广播日。例如:2015 年 11 月 15 日的节目从早上 06:00 开始,到第二天早上 05:00 结束。
下面是一个示例代码,展示了日程安排的样子:
read.table(textConnection("Sunday|\n 01-Nov-15|\n 6|Tom\n some information about the program|\n 23.3|Jerry\n some information about the program|\n 5|Avatar\n some information about the program|\nMonday|\n 02-Nov-15|\n 6|Tom\n some information about the program|\n 23.3|Jerry\n some information about the program|\n 5|Avatar\n some information about the program|"), header = F, sep = "|", stringsAsFactors = F)
其输出如下:
V1|V2
Sunday |
01-Nov-15 |
6 | Tom
some information about the program |
23.3 | Jerry
some information about the program |
5 | Avatar
some information about the program |
5.3 | Panda
some information about the program |
Monday |
02-Nov-15|
6 Jerry
some information about the program |
6.25 | Panda
some information about the program |
23.3 | Avatar
some information about the program |
7.25 | Tom
some information about the program |
我想把上面的数据转换成data.frame的形式
Date |Program|Synopsis
2015-11-1 06:00 |Tom | some information about the program
2015-11-1 23:30 |Jerry | some information about the program
2015-11-2 05:00 |Avatar | some information about the program
2015-11-2 05:30 |Panda | some information about the program
2015-11-2 06:00 |Jerry | some information about the program
2015-11-2 06:25 |Panda | some information about the program
2015-11-2 23:30 |Avatar | some information about the program
2015-11-3 07:25 |Tom | some information about the program
感谢有关我应该查看的功能或软件包的任何建议/提示。
【问题讨论】:
-
@akrun 不,它是一个简单的 csv 文件。我只是添加了 '|'显示列的分隔。
-
感谢您的留言。看起来你已经有了解决方案。所以,我没有尝试这个。