[英]error with double dot `..`in R data.table
earlier today i was looking for a way to get a vector of the names of all columns that are class character in a data.table in R.今天早些时候,我正在寻找一种方法来获取 R 中的 data.table 中的 class 字符的所有列的名称向量。 I found this solution:
我找到了这个解决方案:
> chrs <- sapply(BTplan, is.character)
> chrs
plan plannext noinsnext claimsnext regionnext noins1
TRUE TRUE FALSE FALSE TRUE FALSE
noins2 noins3 region1 region2 region3 claims1
FALSE FALSE TRUE TRUE TRUE FALSE
claims2 claims3 quotationYear historicalYear1 historicalYear2 historicalYear3
FALSE FALSE FALSE FALSE FALSE FALSE
policy planNr combined.PriceAnnually experienceBased.PriceAnnually referenceBased.PriceAnnually errorMessage
TRUE TRUE FALSE FALSE FALSE TRUE
size
FALSE
> chrCols <- names(BTplan[, ..chrs])
it worked earlier today, but now, for some reason I am getting an error:它今天早些时候工作,但现在,由于某种原因,我收到了一个错误:
Error in `[.data.frame`(BTplan, , ..chrs) : object '..chrs' not found
What is the problem?问题是什么? Why does the
..
no longer work?为什么
..
不再起作用?
Based on the error, the 'BTplan' may still be a data.frame
.根据错误,“BTplan”可能仍然是
data.frame
。 Converting to data.table
with setDT
or as.data.table
should fix it as the ..
and the syntax is specific for a data.table
object使用
setDT
或as.data.table
..
data.table
data.table
library(data.table)
names(as.data.table(BTplan)[, ..chrs])
Using a reproducible example使用可重现的示例
chrs <- sapply(iris, is.numeric)
names(as.data.table(iris)[, ..chrs])
#[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.