在R中导入FORTRAN数据的问题 [英] Problems with importing FORTRAN data in R

查看:101
本文介绍了在R中导入FORTRAN数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 .DAT文件显然来自FORTRAN.我尝试过:

I have this .DAT file apparently from FORTRAN. I tried:

read.fortran("ANDRICH.DAT",header = TRUE, format="8F1.0")

但不起作用.我收到以下错误消息:

but is not working. I am getting the following error message:

Error in read.table(file = FILE, header = header, sep = sep, 
row.names = row.names,  : 
more columns than column names

有什么想法吗? 预先感谢!

Any ideas? Thanks in advance!

数据文件如下:

$ 8
$ HIDEOUS
$ LIFESACRED
$ INEFFECTIV
$ DONTBELIEV
$ WISHNOTNEC
$ MUSTHAVEIT
$ DETERRENT
$ CRIMDESERV
$ (8f1.0)
01100000
01100000
01100000
01100000

推荐答案

根据一些Google搜索:

According to some Googling:

这些数据的FORTRAN输入格式为(8F1.0),其中"F1.0"表示 变量存储在一列中,并且没有隐式 小数点.重复此格式,空格不重复8次. 数据集中有8个变量."

"The FORTRAN input format for these data is (8F1.0) where "F1.0" means that a variable is stored in one column and that there are no implicit decimals. This format is reiterated without any space 8 times for the 8 variables in the data set."

来源

跳过第一行,直到您找到实际数据,并使用文件8F1.0中指定的格式:

Skip the first lines until you hit actual data, and use the format specified in the file 8F1.0:

output <- read.fortran("ANDRICH.DAT", format="8F1.0", skip=10)

您可以使用readLines来获取名称:

And you could grab the names using readLines:

names(output) <- gsub("\\$ ","",readLines("ANDRICH.DAT",n=9)[-1])

结果:

#  HIDEOUS LIFESACRED INEFFECTIV DONTBELIEV WISHNOTNEC MUSTHAVEIT DETERRENT CRIMDESERV
#1       0          1          1          0          0          0         0          0
#2       0          1          1          0          0          0         0          0
#3       0          1          1          0          0          0         0          0
#4       0          1          1          0          0          0         0          0
#etc

这篇关于在R中导入FORTRAN数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆