Applying a function over consecutive pairs of list elements in R without loops
问题 I am trying to find an efficient (i.e. avoid using loops) way to apply a function that iteratively takes as arguments the current and previous (or next) elements of a list and returns a lists of the result (the length of which will necessarily be 1 element shorter). As a concrete example, I have a list of vertices defining a path in some graph vlist <- c(1,2,7,12,17) which come from a lattice graph constructed using the igraph function "lattice" G <- graph.lattice(c(5,7)) I want to apply the