Make list of vectors by joining pair-corresponding elements of 2 vectors efficiently in R

后端 未结 1 1069
时光取名叫无心
时光取名叫无心 2020-12-19 01:09

I have 2 vectors:

v1 <- letters[1:5]
v2 <- as.character(1:5)

> v1
[1] \"a\" \"b\" \"c\" \"d\" \"e\"
> v2
[1] \"1\" \"2\" \"3\" \"4\" \"5\"


        
相关标签:
1条回答
  • 2020-12-19 01:19
    mapply(c, v1, v2, SIMPLIFY = FALSE)
    #$a
    #[1] "a" "1"
    
    #$b
    #[1] "b" "2"
    
    #$c
    #[1] "c" "3"
    
    #$d
    #[1] "d" "4"
    
    #$e
    #[1] "e" "5"
    

    (OR more precisely with respect to your OP which returns an unnamed list use mapply(c, v1, v2, SIMPLIFY = FALSE, USE.NAMES = FALSE) ).

    0 讨论(0)
提交回复
热议问题