R data.table fread使用没有标题的命名colClasses(例如没有col.names?) [英] R data.table fread using named colClasses without header (e.g. no col.names?)
问题描述
col.names已添加到data.table 1.9.6上,所以问题已经结束,大家都超级开心:)我想我现在可以将所有我的read.csv调用转换为fread调用而不用担心破坏
col.names was added on data.table 1.9.6 so issue is over and everyone super happy :) I think I can now convert all my read.csv calls to fread calls without worries of destruction
1.9.4
由于我们注意到了巨大的性能改进,我正在将read.csv调用导入fread。大多数问题我可以处理,但我已经达到了一个点,我无知,想知道是否有人有一个elegent解决方案。
I'm importing read.csv calls to fread due to HUGE performance improvements we've noticed. Most issues I can handle but I've reached a point where I'm clueless and wonder if anyone has an elegent solution.
我的问题是,我命名colClasses,但输入没有标题(它是一个grep函数),这里是一个愚蠢的例子有意义:
My problem is that I have named colClasses but the input has no header (it's a grep function), here's a silly example to make sense:
males.students <- read.csv(pipe("grep Male students.csv"),
col.names=c("id", "name", "gender"),
colClasses=(id="numeric"))
现在在fread我还想要命名的colClasses但我没有col名称, / p>
now in fread I still want the named colClasses but I have no col names so just using
males.students <- fread("grep Male students.csv"),
colClasses=(id="numeric"))
失败,
未找到colClasses [[1]]中的列名'id'
Column name 'id' in colClasses[[1]] not found
如何解决?是否有计划添加col.names?
How can I fix that? are there plans to add col.names?
推荐答案
在命令行中添加名称:
fread('echo "id,name,gender"; grep Male students.csv', colClasses = c(id='numeric'))
这篇关于R data.table fread使用没有标题的命名colClasses(例如没有col.names?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!