View source: R/firstContinue.R
firstContinue | R Documentation |
The first/last values in a number sequence with a certain step
firstContinue(v = p0, step = 1, last = FALSE, showWarning = TRUE)
v |
a numeric vector. |
step |
numeric, the step in the number sequence that you are interested |
last |
logical, if TRUE the last values in the sequence are returned. Default is FALSE, by which the first values are returned. |
showWarning |
logical, whether to show warning. Default is TRUE. |
a vector of first/last values in the sequence with a certain step. This vector also contains an attribute (index), which shows the index of these first/last values in the vector v.
# Number sequence is: (1, 2, 3), (5, 6, 7, 8, 9), (12), (22)
x = c(1:3, 5:9, 12, 22)
print(x)
# to show the first values in a number sequence with step = 1
firstContinue(x)
# To show the last values in a number sequence with step = 1
firstContinue(x, last = TRUE)
# (100), (10, 9), (3, 2, 1), (-10)
x = c(100, 10, 9, 3, 2, 1, -10)
print(x)
# To show the first values in a number sequence with step = 1
firstContinue(x, -1)
# to show the last values in a number sequence with step = 1
firstContinue(x, -1, last = TRUE)
x = c(100, 10, 9, 3, 3, 3, 2, 1, 1, 1, -10)
# when step is 0, it is equivalent to unique function.
firstContinue(x, 0)
unique(x)
# When x is not sorted, by default a warning will be raised
# (100), (10, 9), (3, 2, 1), (11, 10), (-10)
x = c(100, 10, 9, 3, 2, 1, 11, 10, -10)
print(x)
firstContinue(x, -1)
# To suppress warning
firstContinue(x, -1, showWarning = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.