r - data.table operations by column name with spaces fails -
reproducible example
#use iris data set library(data.table) iris  colnames(iris)[3] <- "petal length" iris <- as.data.table(iris) accessing column without space fine
iris[,petal.width] however access column name contains space doesn't work
iris[,petal length] iris[,'petal length'] the solution seems be
iris[,iris$'petal length'] comments i'm new data.table. understand there's lot of quirks in data.table; 1 of them? change variable names rid of spaces, i'd prefer not if didn't need to. read previous questions regarding column names - , understand in 2 years since last question updates have allowed - can seen in ease when colname has no spaces.
just use with = false explained under data.table faq points 1.1-1.3 , 2.17:
iris[ ,'petal length', = false] and make sure read excellent introduction data.table pdf vignette , new html vignettes.
in case, expect (a vector), using [[ more appropriate:
iris[['petal length']] alternatively, can refer column names if variables in j:
iris[, `petal length`] # note backticks. 
Comments
Post a Comment