从data.table中获取字符串的列 [英] Get columns by string from data.table

查看:88
本文介绍了从data.table中获取字符串的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

raw data.table ,并且以下代码适用:

raw is a data.table and the following code works:

raw[,r_responseTime] #Returns the whole column
raw[,c_filesetSize]  #Same as above, returns column
plot(raw[,r_responseTime]~raw[,c_filesetSize]) #draws something

例如:

col1="r_reponseTime"
col2="c_filesetSize"

如何通过字符串引用列来实现上述方法?

How can I now achieve the same as above while referencing the columns by the string?

raw[,col1] #Returns the whole column
raw[,col2]  #Same as above, returns column
plot(raw[,col1]~raw[,col2]) #draws something

种类的解除关联。

推荐答案

这将是一个很好的解决方案。如果你提供了一个可重现的例子,或者至少显示了 raw 的列名是什么以及 r_responseTime c_filesetSize 包含。这就是说, get 是您解除引用的函数,所以请尝试:

It would be nice if you had provided a reproducible example, or at the very least shown what the column names of raw are and what r_responseTime and c_filesetSize contain. This being said, get is your function for dereferencing so give these a try:

raw[, get(col1)]
raw[, get(col2)]
plot(raw[, get(col1)] ~ raw[, get(col2)])

这篇关于从data.table中获取字符串的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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