And here is another solution using stri_split_fixed from stringi package. As an added value, we also play with mapply and do.call .
Input data:
mintimes <- c("3121|3151", "1171", "1351|1381", "1050", "", "122") minvalues <- c(14, 10, 11, 31, Inf, 22)
Split mintimes wrt | and convert to numeric:
library("stringi") mintimes <- lapply(stri_split_fixed(mintimes, "|"), as.numeric)
The column associates each minvalues with the corresponding mintimes :
tmp <- mapply(cbind, mintimes, minvalues) ## [[1]] ## [,1] [,2] ## [1,] 3121 14 ## [2,] 3151 14 ## ## [[2]] ## [,1] [,2] ## [1,] 1171 10 ## ## [[3]] ## [,1] [,2] ## [1,] 1351 11 ## [2,] 1381 11 ## ## [[4]] ## [,1] [,2] ## [1,] 1050 31 ## ## [[5]] ## [,1] [,2] ## [1,] NA Inf ## ## [[6]] ## [,1] [,2] ## [1,] 122 22
Link-link all 6 matrices and remove NA -rows:
res <- do.call(rbind, tmp) res[!is.na(res[,1]),] ## [,1] [,2] ## [1,] 3121 14 ## [2,] 3151 14 ## [3,] 1171 10 ## [4,] 1351 11 ## [5,] 1381 11 ## [6,] 1050 31 ## [7,] 122 22