提问人:rjuuser 提问时间:9/8/2009 更新时间:9/8/2009 访问量:854
使用可变长度从文本文件(用空格分隔)获取数据到 R 中
Getting data from text file (separated by spaces) using variable lengths into R
问:
我有一个类似于这样的文本文件(用空格分隔):
x <- "DF12 This is an example 1 This
DF12 This is an 1232 This is
DF14 This is 12334 This is an
DF15 This 23 This is an example
"
我知道每个变量的字段长度(这个数据集中有 5 个变量),它们是:
varlength <- c(2, 2, 18, 5, 18)
如何使用 varlength 变量作为字段分隔符指示器将此类数据导入 R?
答:
2赞
Dirk is no longer here
9/8/2009
#1
根据巴里·罗林森(Barry Rowlingson)在r-help上的说法(您似乎已经交叉发布):
?read.fwf
读取固定宽度格式化文件
描述:
Read a table of *f*ixed *w*idth *f*ormatted data into a 'data.frame'.
用法:
read.fwf(file, widths, header = FALSE, sep = "\t", skip = 0, row.names, col.names, n = -1, buffersize = 2000, ...)
评论