Description Usage Arguments Value Author(s) Examples
This functions takes a vector and removes duplicate, neighbouring entries. Indices are preserved under this operation. If you encounter a sequence of equal values within a vector, the first one is preserved and its right neighbours are removed.
1 |
vec |
Vector of type double - The input vector. |
order |
Boolean - Value indicating wether resulting dataframe should be sorted in decreasing order (defaults to TRUE). |
A data frame with two columns. 1st column $values: The resulting vector. 2nd column $indices: The corresponding indices matching the input vector.
P.v.W. Crommelin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | vec = c(1,1,3,4,5,6,7,7,7,7,7,8,9,10,9,8,7,6,5,4,4,4,4,3,2,1)
N = length(vec)
plot(x = 1:N,
y = vec,
type = "l",
main = "demonstration")
points(x = 1:N,
y = vec)
collapsedVec = collapse(vec = vec,
order = FALSE)
lines(x = collapsedVec$indices,
y = collapsedVec$values,
col = "red")
points(x = collapsedVec$indices,
y = collapsedVec$values,
col = "red")
legend("topright",
leg = c("original vector","collapsed vector"),
col = c("black","red"),
lty = 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.