Skip to content

Commit 7c6b9c8

Browse files
committed
changed directory
1 parent aa0ecc0 commit 7c6b9c8

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

man/data.table.Rd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,24 @@ setkeyv(kDT,v) # same
350350
haskey(kDT) # TRUE
351351
key(kDT) # "x"
352352

353+
# Keyed subsetting (no 'on' needed)
354+
setkey(kDT, x) # Set a key on column 'x'
355+
kDT[.("a")] # Returns all rows where x = "a"
356+
357+
# Indexed subsetting (requires 'on')
358+
setindex(kDT, x) # Set an index on column 'x'
359+
kDT[.("b"), on = "x"] # Works, returns all rows where x = "b" (for detailed explanation visit setkey.rd)
360+
# kDT[.("b")] # this will throw error
361+
362+
# single and multiple indices
363+
# index on a single column ('y')
364+
setindex(kDT, y)
365+
indices(kDT)
366+
367+
# multi-column index
368+
setindexv(kDT, list("x", c("x", "y")))
369+
indices(kDT) # Shows an index on 'x' and a composite index on '(x,y)'
370+
353371
# fast *keyed* subsets
354372
kDT["a"] # subset-as-join on *key* column 'x'
355373
kDT["a", on="x"] # same, being explicit using 'on=' (preferred)

man/setkey.Rd

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,6 @@ setindex(DT, A)
155155
setindex(DT, B)
156156
indices(DT) # get indices single vector
157157
indices(DT, vectors = TRUE) # get indices list
158-
159-
# Keyed subsetting (no 'on' needed)
160-
DT = data.table(A=5:1,B=letters[5:1])
161-
setkey(DT, B)
162-
DT[.("e")] # Returns row where B = "e"
163-
164-
# Indexed subsetting (requires 'on')
165-
DT = data.table(A=5:1,B=letters[5:1])
166-
setindex(DT, B)
167-
DT[.("e"), on = "B"] # Works
168-
# DT[.("e")] # Would error (missing 'on')
169-
170-
DT <- data.table(a = c(1,2,1,2), b = c("x", "x", "y", "y"), val = 1:4)
171-
# Set an index on a single column
172-
setindex(DT, a)
173-
# Set multiple indices at once using setindexv
174-
setindexv(DT, list("a", c("a", "b")))
175158

176159
# Setting multiple indices at once
177160
DT = data.table(A = 5:1, B = letters[5:1], C = 10:6)

0 commit comments

Comments
 (0)