gpt4 book ai didi

读取 HITRAN 文件格式

转载 作者:行者123 更新时间:2023-12-04 18:18:59 27 4
gpt4 key购买 nike

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))

指定正确格式的任何提示?

最佳答案

根据 ?read.fortran :

  • "E"不是受支持的格式。
  • “在 'F' 或 'D' 格式中指定 'd > 0' 将改变
    小数点“d”在左边,即使它是明确的
    在输入文件中指定。”

  • 所以改变 "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)

    关于读取 HITRAN 文件格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11091850/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com