【发布时间】:2015-12-11 16:44:56
【问题描述】:
我想读取一个文件,其中每一行代表一个包含日期、一些文本和数字的数据集。示例:
Fri Dec 11 12:40:01 CET 2015 Uptime: 108491 Threads: 2 Questions: 576603 Slow queries: 10 Opens: 2238 Flush tables: 1 Open tables: 7 Queries per second avg: 5.314
Fri Dec 11 12:50:01 CET 2015 Uptime: 109090 Threads: 2 Questions: 580407 Slow queries: 10 Opens: 2253 Flush tables: 1 Open tables: 6 Queries per second avg: 5.320
Fri Dec 11 13:00:01 CET 2015 Uptime: 109690 Threads: 2 Questions: 583895 Slow queries: 10 Opens: 2268 Flush tables: 1 Open tables: 8 Queries per second avg: 5.323
Fri Dec 11 13:10:01 CET 2015 Uptime: 110290 Threads: 1 Questions: 586891 Slow queries: 10 Opens: 2279 Flush tables: 1 Open tables: 6 Queries per second avg: 5.321
Fri Dec 11 13:20:01 CET 2015 Uptime: 110890 Threads: 2 Questions: 590871 Slow queries: 10 Opens: 2292 Flush tables: 1 Open tables: 5 Queries per second avg: 5.328
没有通用的分隔字符(如 CSV 中),但格式可以很好地描述,因为可以使用制表符、字符和文本。
%DATESTRING%\tUptime: %uptime% Threads: %threads% Questions: %questions% Slow queries: %slow% Opens: %opens% Flush tables: %flush% Open tables: %otables% Queries per second avg: %qps%
是否有一个函数可以获取格式和文件的描述并用给定的数据填充 data.frame?
【问题讨论】:
-
我很幸运地将它放入 excel 中,在需要的地方修复它,然后将其保存为 csv。
-
@rawr 列名包含在行记录中的事实对于我使用过的固定宽度是非标准的......
-
@MichaelChirico 是的,你是对的
-
@rawr 我仍然认为这种方法有效——读取为固定宽度,然后从列名中提取子集
标签: r data-import fileparsing