number_line {diyar} R Documentation

## number_line

### Description

A range of numeric values.

### Usage

number_line(l, r, id = NULL, gid = NULL)

as.number_line(x)

is.number_line(x)

left_point(x)

left_point(x) <- value

right_point(x)

right_point(x) <- value

start_point(x)

start_point(x) <- value

end_point(x)

end_point(x) <- value

number_line_width(x)

reverse_number_line(x, direction = "both")

shift_number_line(x, by = 1)

expand_number_line(x, by = 1, point = "both")

invert_number_line(x, point = "both")

number_line_sequence(
x,
by = NULL,
length.out = 1,
fill = TRUE,
simplify = FALSE
)


### Arguments

 l [numeric based]. Left point of the number_line. Must be able to be coerced to a numeric object. r [numeric based]. Right point of the number_line. Must be able to be coerced to a numeric object. id [integer]. Unique element identifier. Optional. gid [integer]. Unique group identifier. Optional. x [number_line] value [numeric based] direction [character]. Type of "number_line" objects to be reversed. Options are; "increasing", "decreasing" or "both" (default). by [integer]. Increment or decrement. Passed to seq() in number_line_sequence() point [character]. "start", "end", "left" or "right" point. length.out [integer]. Number of splits. For example, 1 for two parts or 2 for three parts. Passed to seq() fill [logical]. Retain (TRUE) or drop (FALSE) the remainder of an uneven split simplify [logical]. Split into number_line or sequence of finite numbers

### Details

A number_line represents a range of numbers on a number line. It is made up of a start and end point which are the lower and upper ends of the range respectively. The location of the start point - left or right, determines whether it is an "increasing" or "decreasing" range. This is the direction of the number_line.

reverse_number_line() - reverses the direction of a number_line. A reversed number_line has its left and right points swapped. The direction argument specifies which type of number_line will be reversed. number_line with non-finite start or end points (i.e. NA, NaN and Inf) can't be reversed.

shift_number_line() - Shift a number_line towards the positive or negative end of the number line.

expand_number_line() - Increase or decrease the width of a number_line.

invert_number_line() - Change the left or right points from a negative to positive value or vice versa.

number_line_sequence() - Split a number_line into equal parts (length.out) or by a fixed recurring width (by).

### Value

number_line

overlaps; set_operations; episodes; links

### Examples

date <- function(x) as.Date(x, "%d/%m/%Y")
dttm <- function(x) as.POSIXct(x, "UTC", format = "%d/%m/%Y %H:%M:%S")

number_line(-100, 100)

# Also compatible with other numeric based object classes
number_line(dttm("15/05/2019 13:15:07"), dttm("15/05/2019 15:17:10"))

# Coerce applicable object classes to number_line objects
as.number_line(5.1); as.number_line(date("21/10/2019"))

# A test for number_line objects
a <- number_line(date("25/04/2019"), date("01/01/2019"))
is.number_line(a)

# Structure of a number_line object
left_point(a); right_point(a); start_point(a); end_point(a)

# Reverse number_line objects
reverse_number_line(number_line(date("25/04/2019"), date("01/01/2019")))
reverse_number_line(number_line(200, -100), "increasing")
reverse_number_line(number_line(200, -100), "decreasing")

c <- number_line(5, 6)
# Shift number_line objects towards the positive end of the number line
shift_number_line(x = c(c, c), by = c(2, 3))
# Shift number_line objects towards the negative end of the number line
shift_number_line(x = c(c, c), by = c(-2, -3))

# Change the duration, width or length of a number_line object
d <- c(number_line(3, 6), number_line(6, 3))

expand_number_line(d, 2)
expand_number_line(d, -2)
expand_number_line(d, c(2,-1))
expand_number_line(d, 2, "start")
expand_number_line(d, 2, "end")

# Invert number_line objects
e <- c(number_line(3, 6), number_line(-3, -6), number_line(-3, 6))
e
invert_number_line(e)
invert_number_line(e, "start")
invert_number_line(e, "end")

# Split number line objects
x <- number_line(Sys.Date() - 5, Sys.Date())
x
number_line_sequence(x, by = 2)
number_line_sequence(x, by = 4)
number_line_sequence(x, by = 4, fill = FALSE)
number_line_sequence(x, length.out = 2)


[Package diyar version 0.4.1 Index]