Reproducible example
#Use the Iris data set
library(data.table)
iris
colnames(iris)[3] <- "Petal Length"
iris <- as.data.table(iris)
Accessing column without space is fine
iris[,Petal.Width]
however access a column where the name contains a space doesn't work
iris[,Petal Length]
iris[,'Petal Length']
The only solution seems to be
iris[,iris$'Petal Length']
Comments I'm new to data.table. I understand there's a lot of quirks in data.table; is this one of them? I would change my variable names to get rid of spaces, but I'd prefer not to if i didn't need to. I also read a previous questions regarding just column names - and I understand in the two years since that last question updates have allowed it - this can be seen in the ease when the colname has no spaces.
petal_length,petal.lengthandpetalLength- MichaelChirico