Let's say I have the following vector of numbers:
vec = c(1, 2, 3, 5, 7, 8, 9, 10, 11, 12)
I'm looking for a function that will create a string summarizing the list of numbers the way a human would. That is, each run of consecutive numbers (here 1, 2, 3
and 7, 8, 9, 10, 11, 12
) is collapsed into its start and end value:
"1-3, 5, 7-12"
How can I do this in R?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…