head, tail, .
c(tail(x, -1), head(x, 1))
, , . , :
x <- c("a", "b", "c", "d", "e")
gagolews <- function() c(x[-1], x[1])
senoro <- function() x[c(2:length(x), 1)]
tyler <- function() c(tail(x, -1), head(x, 1))
ananda <- function() shifter(x, 1)
user <-function(){
firstVal = x[1]
x = tail(x,-1)
x[length(x)+1] = firstVal
x
}
library(microbenchmark)
(op <- microbenchmark(
gagolews(),
senoro(),
tyler(),
ananda(),
user(),
times=100L))
Here I expanded. I only downloaded 100 reps due to the size of the vector (1 million characters).
x <- rep(c("a", "b", "c", "d", "e"), 1000000)
## Unit: milliseconds
## expr min lq median uq max neval
## gagolews() 168.9151 171.3631 179.0490 193.9604 260.5963 100
## senoro() 192.2669 203.9596 259.1366 272.5570 341.4443 100
## tyler() 237.4218 246.5368 303.5700 319.3999 347.3610 100
## ananda() 237.9610 247.2097 303.9898 318.4564 342.2518 100
## user() 225.4503 234.3431 287.8348 300.8078 319.2051 100

source
share