Combine columns A, B element by element into list-column of ranges from the elements of A and B

You can use

library(data.table)
d[, my_wanted_col := Map(`:`, A, B)]
d

#   A B my_wanted_col
#1: 1 5     1,2,3,4,5
#2: 2 6     2,3,4,5,6
#3: 3 7     3,4,5,6,7

data

d <- data.table(A=c(1,2,3),B=c(5,6, 7))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top