也可以将文件读入内存,
> buffer <- readLines ("tmp/file")
> buffer
[1] "0 0 0" "0 0 0"
[3] "" ""
[5] "54077 184965 81.25" "54266 184776 81.25"
[7] "" ""
[9] "65130 199986 82.1705426356589" "65513 199600 82.1705426356589"
删除或处理(例如导出测量编号、数据集名称……)所有不属于数据表文件部分的行:
> buffer <- buffer [nzchar (buffer) > 0L]
> buffer
[1] "0 0 0" "0 0 0"
[3] "54077 184965 81.25" "54266 184776 81.25"
[5] "65130 199986 82.1705426356589" "65513 199600 82.1705426356589"
最后read.table
在修改后的缓冲区上使用:
> read.table (textConnection (buffer))
V1 V2 V3
1 0 0 0.00000
2 0 0 0.00000
3 54077 184965 81.25000
4 54266 184776 81.25000
5 65130 199986 82.17054
6 65513 199600 82.17054