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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -