在R中读取键值文件 [英] Reading a key-value file in R
本文介绍了在R中读取键值文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以读取R中的简单文本键值文件...
Is there a way to read a simple text key-value file in R ...
Key1=Value1
Key2=Value2
Key3=Value3
理想情况下,我想这样访问数据:
Ideally I want to access the data like this:
myfile $ Key1应该返回Value1,myfile @ Key2应该返回Value2
等等
myfile$Key1 should return Value1 , myfile@Key2 should return Value2
and so on
干杯! MadSeb
Cheers! MadSeb
P.S我研究了stashR和filehash软件包,尽管这些软件包实现了不错的键值数据库,但它们并未以简单/可读的文本格式存储数据库.
P.S I looked into the stashR and the filehash packages and while these packages implement nice key value databases, they don't store the database in simple/readable text format.
推荐答案
类似这样的事情:
dframe <- read.table(file='yourfile.txt',header=FALSE,
sep='=',col.names=c('Key','Value'))
然后,如果您想通过密钥更快地访问,则可以使用data.table,例如:
then, if you want a faster access by key, you can use data.table e.g. :
library(data.table)
dframe <- read.table(file='yourfile.txt',header=FALSE,
sep='=',col.names=c('Key','Value'))
dtable <- data.table(dtfrm,key='Key')
dtable['Key1']
这篇关于在R中读取键值文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文