Skip to content

Commit 823433b

Browse files
committed
added example
1 parent 0f821fe commit 823433b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

man/data.table.Rd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ A \code{data.table} is a \code{list} of vectors, just like a \code{data.frame}.
231231
232232
See the \code{see also} section for the several other \emph{methods} that are available for operating on data.tables efficiently.
233233
234+
235+
A \code{data.table} supports joins on columns of type \code{complex}. The join logic is as follows:
236+
\itemize{
237+
\item If a \code{complex} column contains values with only a zero imaginary part (e.g., \code{10+0i}), it is treated as a \code{double} for the join, allowing it to match with \code{integer} and \code{double} columns successfully.
238+
\item If any value in a \code{complex} join column has a non-zero imaginary part (e.g., \code{10+2i}), the join will stop with an error, as there is no defined way to sort or match such a number against a real number.
239+
}
234240
}
235241
\references{
236242
\url{https://r-datatable.com} (\code{data.table} homepage)\cr
@@ -441,6 +447,27 @@ DT[, c(.(y=max(y)), lapply(.SD, min)), by=rleid(v), .SDcols=v:b]
441447
# Support guide and links:
442448
# https://github.com/Rdatatable/data.table/wiki/Support
443449

450+
# Example: Joining with a system that uses complex IDs (#6627)
451+
452+
# Case 1: Success - Joining a "clean" set of products.
453+
# Here, `products_clean` only contains IDs with zero imaginary parts.
454+
products_clean = data.table(id = c(101+0i, 103+0i), name = c("widget", "thingamajig"))
455+
sales = data.table(product_id = c(101, 103), units_sold = c(50, 75))
456+
457+
# This join works because the 'id' column in `products_clean` has no non-zero imaginary parts.
458+
products_clean[sales, on = .(id = product_id), nomatch = 0]
459+
460+
# Case 2: Error - Joining a list that includes "bad" IDs.
461+
# Here, `products_all` contains an ID with a non-zero imaginary part (102+1i).
462+
products_all = data.table(id = c(101+0i, 102+1i, 103+0i), name = c("widget", "gadget", "thingamajig"))
463+
464+
# The join fails because the entire 'id' column is checked first.
465+
try(products_all[sales, on = .(id = product_id), nomatch = 0])
466+
467+
\dontshow{
468+
rm(products_clean, sales, products_all)
469+
}
470+
444471
\dontrun{
445472
if (interactive()) {
446473
vignette(package="data.table") # 9 vignettes

0 commit comments

Comments
 (0)