Skip to content

Instantly share code, notes, and snippets.

@nilforooshan
Created March 11, 2024 21:15
Show Gist options
  • Save nilforooshan/f54b367f9e8d170e58222e6e75be2b35 to your computer and use it in GitHub Desktop.
Save nilforooshan/f54b367f9e8d170e58222e6e75be2b35 to your computer and use it in GitHub Desktop.
R: Three ways of extracting a data.table column as a vector

Three ways of extracting a data.table column as a vector

DT = data.table(
    ID = c("b","b","b","a","a","c"),
    a = 1:6,
    b = 7:12,
    c = 13:18
)
DT[[1]]
DT$ID
DT[,ID]
[1] "b" "b" "b" "a" "a" "c"
[1] "b" "b" "b" "a" "a" "c"
[1] "b" "b" "b" "a" "a" "c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment