How to cross-paste all combinations of two vectors (each-to-each)?

后端 未结 4 1413
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 06:04

I need to paste all combinations of elements from two character vectors, \"each\" to \"each\": instead of

> paste0(c(\"a\", \"b\"), c(\"c\", \"d\"))
[1]          


        
4条回答
  •  情歌与酒
    2020-12-09 06:24

    This can also be used.

    comb <- function(x,y) 
             {
              x1 <- rep(x, each=length(y))
              y1 <- rep(y, times=length(x))
              paste0(x1,y1)
             }
    comb(2:4, 5:7)
    

提交回复
热议问题