new_seq | R Documentation |
Generate a new sequence of values. A sequence of values is used to predict the effect of a variable.
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'logical'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'integer'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'double'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'character'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'factor'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'ordered'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'Date'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'POSIXct'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
## S3 method for class 'hms'
new_seq(x, length_out = NULL, ..., obs_only = NULL)
x |
The object to generate the sequence from. |
length_out |
The maximum length of the sequence. |
... |
These dots are for future extensions and must be empty. |
obs_only |
A flag specifying whether to only use observed values. |
By default the sequence of values for objects of class numeric
is 30 evenly space values across the range of the data.
Missing values are always removed unless it's the only value
or the object is zero length.
The length of the sequence can be varied using the length_out
argument
which gives the reference value when 1 and can even be 0.
For integer objects the sequence is the unique integers.
For character objects it's the actual values sorted by
how common they are followed by their actual value.
For factors it's the factor levels in order
with the trailing levels dropped first.
For ordered factors the intermediate levels are dropped first.
For Date vectors it's the unique dates;
same for hms vectors.
For POSIXct vectors the time zone is preserved.
For logical objects the longest possible sequence is c(TRUE, FALSE)
.
A vector of the same class as the object.
new_seq(logical)
: Generate new sequence of values for logical objects
new_seq(integer)
: Generate new sequence of values for integer objects
new_seq(double)
: Generate new sequence of values for double objects
new_seq(character)
: Generate new sequence of values for character objects
new_seq(factor)
: Generate new sequence of values for factors
new_seq(ordered)
: Generate new sequence of values for ordered factors
new_seq(Date)
: Generate new sequence of values for Date vectors
new_seq(POSIXct)
: Generate new sequence of values for POSIXct vectors
new_seq(hms)
: Generate new sequence of values for hms vectors
new_value()
and new_data()
.
# by default the sequence of values for objects of class numeric
# is 30 evenly space values across the range of the data
new_seq(c(1, 4))
# missing values are always removed
new_seq(c(1, 4, NA))
# unless it's the only value
new_seq(NA_real_)
# or the object is zero length
new_seq(numeric())
# the length of the sequence can be varied using the length_out argument
new_seq(c(1, 4), length_out = 3)
new_seq(c(1, 4), length_out = 2)
# which gives the reference value when 1
new_seq(c(1, 4), length_out = 1)
# and can even be 0
new_seq(c(1, 4), length_out = 0)
# for integer objects the sequence is the unique integers
new_seq(c(1L, 4L))
new_seq(c(1L, 100L))
# for character objects it's the actual values sorted by
# how common they are followed by their actual value
new_seq(c("a", "c", "c", "b", "b"))
new_seq(c("a", "c", "c", "b", "b"), length_out = 2)
# for factors its the factor levels in order
new_seq(factor(c("a", "b", "c", "c"), levels = c("b", "a", "g")))
# with the trailing levels dropped first
new_seq(factor(c("a", "b", "c", "c"), levels = c("b", "a", "g")),
length_out = 2
)
# for ordered factors the intermediate levels are dropped first
new_seq(ordered(c("a", "b", "c", "c"), levels = c("b", "a", "g")),
length_out = 2
)
# for Date vectors it's the unique dates
new_seq(as.Date(c("2000-01-01", "2000-01-04")))
# same for hms vectors
new_seq(hms::as_hms(c("00:00:01", "00:00:04")))
# for POSIXct vectors the time zone is preserved
new_seq(as.POSIXct(c("2000-01-01 00:00:01", "2000-01-01 00:00:04"),
tz = "PST8PDT"
))
# for logical objects the longest possible sequence is `c(TRUE, FALSE)`
new_seq(c(TRUE, TRUE, FALSE), length_out = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.