Pasting elements of two vectors alphabetically
slightly redundant because it sorts twice, but vectorised, paste(pmin(a,b), pmax(a,b)) Edit: alternative with ifelse, ifelse(a < b, paste(a, b), paste(b, a))
slightly redundant because it sorts twice, but vectorised, paste(pmin(a,b), pmax(a,b)) Edit: alternative with ifelse, ifelse(a < b, paste(a, b), paste(b, a))
December 2018 update Efficient implementation of adaptive rolling functions has been made in data.table recently – more info in ?froll manual. Additionally an efficient alternative solution using base R has been identified (fastama below). Unfortunately Kevin Ushey’s answer does not address the question thus it is not included in benchmark. Scale of benchmark has been … Read more