Selecting groups or parts of groups
The previous exercise illustrated how you can manually set a key via setkey(DT, A, B). setkey() sorts the data by the columns that you specify and changes the table by reference. Having set a key will allow you to use it, for example, as a super-charged row name when doing selections. Arguments like mult and nomatch then help you to select only particular parts of groups.
For this exercise, we have already created a new data table named DT with keys set to A and B.
# 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)
Este ejercicio forma parte del curso
test subex r
Ejercicio interactivo práctico
Pon en práctica la teoría con uno de nuestros ejercicios interactivos
Empezar ejercicio