changesPos | R Documentation |
Find positions in a vector that have a different value from the previous position.
changesPos(x, include.first = TRUE)
x |
A vector of sorted (generally) values. |
include.first |
A logical that indicates whether the returned vector of positions should have a “1” at the beginning (i.e., by definition the first position is the first position that is different than the previous value). |
A vector of positions in x
where the value differs from the value in the previous position.
Derek H. Ogle, dogle@northland.edu
x <- rep(LETTERS[1:6],times=c(5,4,1,1,2,4)) data.frame(pos=1:length(x),x) # for demonstration only changesPos(x) v <- rep(10:17,times=c(4,1,1,2,4,2,1,1)) data.frame(pos=1:length(v),v) # for demonstration only changesPos(v) ## An uninteresting example -- i.e., vector not sorted z <- sample(10:17,20,replace=TRUE) data.frame(pos=1:length(z),z) # for demonstration only changesPos(z) z1 <- z[order(z)] data.frame(pos=1:length(z1),z1) # for demonstration only changesPos(z1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.