以this file为例,我正在尝试读取data.frame中的数据。从the doc(pdf文件,表1),它遵循一些fortran惯例。我尝试了以下几点但收效甚微:
dir <- "Uncompressed-files/"
file <- "01_hit09.par"
delim <- c("I2", "I1", "F12.6", "E10.3", "E10.3", "F5.4", "F5.4",
"F10.4", "F4.2", "F8.6", "A15", "A15", "A15", "A15", "6I1", "6I2",
"A1", "F7.1", "F7.1")
test <- read.fortran(paste0(dir, file), delim)
test <- read.fwf(paste0(dir, file),
c(2, 1, 12, 10, 10, 5, 5, 10, 4, 8,
15, 15, 15, 15, 6, 12, 1, 7, 7))
指定正确格式的提示吗?
答案 0 :(得分:4)
根据?read.fortran
:
"E"
不支持格式。所以将"E"
更改为"F"
并删除所有显式小数格式:
file <- "01_hit09.par"
delim <- c("I2", "I1", "F12", "F10", "F10", "F5", "F5", "F10", "F4", "F8",
"A15", "A15", "A15", "A15", "6I1", "6I2", "A1", "F7", "F7")
(test <- read.fortran(file, delim, n=10))
更新:或者正确指定宽度并使用read.fwf
:
test2 <- read.fwf(file, c(2,1,12,10,10,5,5,10,4,8,15,15,15,15,
rep(1,6),rep(2,6),1,7,7), as.is=TRUE)