I have a data.table. One of the column is called "High Score". I know we can always rename the column. But is there a way to subset the data based on the column if we have to use quote for the column name? Actually I need do that for a list of this type of columns
I have used iris table to made the following example:
library(data.table)
dt <- as.data.table(iris)
# rename to make the variable with space
setnames(dt, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species"),
c("Sepal Length", "Sepal Width", "Petal Length", "Petal Width", "Species"))
seg_name <- c("Sepal Length", "Sepal Width", "Petal Length", "Petal Width")
Then I want to create a number of subsets based on each column. But all these columns are with space or special char
for (i in 1:length(seg_name)){
# here is the problem !!!
tmp <- dt[seg_name[i] > 6]
fwrite(tmp, paste0('./output/', seg_name[i], '.txt'), row.names = F, sep = "\t")
}
dt[`Sepal Length` > 3]
, don't overwritesubset
, it's a base R function – pogibascust_seg_all
? – MKR