Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

data table R select several columns

# library         
library(data.table)

# generate random data
data <- 
  data.table(
    'Var1' = sample(-100:100, 5), 
    'Var2' = sample(-100:100, 5), 
    'Var3' = sample(-100:100, 5)
  )

# option 1: directly through the variable names
data[, .(Var2, Var3)]

# option 2: using .SD & .SDcols
data[, .SD, .SDcols = c('Var2', 'Var3')]
 
PREVIOUS NEXT
Tagged: #data #table #R #select #columns
ADD COMMENT
Topic
Name
1+5 =