[R] Finding the distance between ordered integers

Dale Steele dale.w.steele at gmail.com
Thu Jan 22 16:07:44 CET 2009


I'm stuck on how best to of find the distance between ordered integers
(presented below as a birthday problem).  Given the vector x, how do I
most efficiently generate the vector x[i+1] - x[i]?  Thanks.  --Dale

For example...
set.seed(555)
x <- sample(1:365, 10, replace=TRUE)
x <- sort(x)

x       x[i+1]-x[i]
---    ---------------
14	
14	0
75	61
136	61
197	61
236	39
253	17
310	57
323	13
355	32




More information about the R-help mailing list