Skip to content

Commit de0cf94

Browse files
Nj221102nitish jhaMichaelChirico
authored
Added Comprehensive Examples for set Function in Documentation (#6190)
* added examples for set function in docs * added examples for set function in docs * Update man/assign.Rd Co-authored-by: Michael Chirico <michaelchirico4@gmail.com> * added examples for set function in docs * make 2nd row non-consecutive to justify using c() --------- Co-authored-by: nitish jha <nitishjha@nitishs-MacBook-Air.local> Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
1 parent f5a1e09 commit de0cf94

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

man/assign.Rd

+15
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ sq_col_idx = grep('d$', names(DT))
140140
DT[ , (sq_col_idx) := lapply(.SD, dnorm),
141141
.SDcols = sq_col_idx]
142142

143+
# Examples using `set` function
144+
## Set value for single cell
145+
set(DT, 1L, "b", 10L)
146+
## Set values for multiple columns in a specific row
147+
set(DT, 2L, c("b", "d"), list(20L, 30L))
148+
## Set values by column indices
149+
set(DT, 3L, c(2L, 4L), list(40L, 50L))
150+
## Set value for an entire column without specifying rows
151+
set(DT, j = "b", value = 100L)
152+
set(DT, NULL, "b", 100L) # equivalent
153+
## Set values for multiple columns without specifying rows
154+
set(DT, j = c("b", "d"), value = list(200L, 300L))
155+
## Set values for multiple columns with multiple specified rows.
156+
set(DT, c(1L, 3L), c("b", "d"), value = list(500L, 800L))
157+
143158
\dontrun{
144159
# Speed example:
145160

0 commit comments

Comments
 (0)