Created
January 7, 2019 09:16
-
-
Save ibarraespinosa/88ad8f4e194ed6631102eae575852a00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The 'keyed' data.table DT | |
DT <- data.table(A = letters[c(2, 1, 2, 3, 1, 2, 3)], | |
B = c(5, 4, 1, 9, 8, 8, 6), | |
C = 6:12) | |
setkey(DT, A, B) | |
# Select the "b" group | |
DT["b"] | |
# "b" and "c" groups | |
DT[c("b", "c")] | |
# The first row of the "b" and "c" groups | |
DT[c("b", "c"), mult = "first"] | |
# First and last row of the "b" and "c" groups | |
DT[c("b", "c"), .SD[c(1, .N)], by = .EACHI] | |
# Copy and extend code for instruction 4: add printout | |
DT[c("b", "c"), { print(.SD); .SD[c(1, .N)] }, by = .EACHI] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment