Learn R Programming

diyar (version 0.2.0)

set_operations: Set operations on number line objects

Description

Perform set operations on a pair of number_line objects.

Usage

union_number_lines(x, y)

intersect_number_lines(x, y)

subtract_number_lines(x, y)

Arguments

x

number_line object

y

number_line object

Value

number_line; list

Details

union_number_lines() - Return a number_line object with the combined range of x and y

intersect_number_line() - Returns a subset of x that overlaps with y and vice versa

subtract_number_lines() - Returns a subset of x that does not overlap with y and vice versa. Returns a list with two elements;

  • n1 - subset before the overlapped range between x and y.

  • n2 - subset after the overlapped range between x and y

The direction of the returned number_line will be that of the widest one (x or y). If x and y have the same length, it'll be an "increasing direction".

If x and y do not overlap, NA ("NA ?? NA") is returned.

See Also

number_line and overlaps

Examples

Run this code
# NOT RUN {
nl_1 <- c(number_line(1, 5), number_line(1, 5), number_line(5, 9))
nl_2 <- c(number_line(1, 2), number_line(2, 3), number_line(0, 6))

# Union
nl_1; nl_2; union_number_lines(nl_1, nl_2)


nl_3 <- number_line(as.Date(c("01/01/2020", "03/01/2020","09/01/2020"), "%d/%m/%Y"),
                    as.Date(c("09/01/2020", "09/01/2020","25/12/2020"), "%d/%m/%Y"))

nl_4 <- number_line(as.Date(c("04/01/2020","01/01/2020","01/01/2020"), "%d/%m/%Y"),
                    as.Date(c("05/01/2020","05/01/2020","03/01/2020"), "%d/%m/%Y"))

# Intersect
nl_3; nl_4; intersect_number_lines(nl_3, nl_4)

# Subtract
nl_3; nl_4; subtract_number_lines(nl_3, nl_4)

# }

Run the code above in your browser using DataLab