R中的zip/unzip函数

R中的zip/unzip函数,r,functional-programming,R,Functional Programming,我正在寻找函数式编程语言(如Haskell、Scala)中的zip/unzip之类的函数 。邮编: 解压缩: Input: unzip [(1,2),(2,3),(3,4)] Output: ([1,2,3],[2,3,4]) 在R中,输入看起来像这样。对于拉链: l1 <- list(1,2,3) l2 <- list(9,8,7) l <- Map(c, l1, l2) l1试图提供大量FP原语purrr的zip版本称为transpose() L1我不认为这正是您想要的

我正在寻找函数式编程语言(如Haskell、Scala)中的zip/unzip之类的函数

。邮编:

解压缩:

Input: unzip [(1,2),(2,3),(3,4)]
Output: ([1,2,3],[2,3,4])
在R中,输入看起来像这样。对于拉链:

l1 <- list(1,2,3)
l2 <- list(9,8,7)
l <- Map(c, l1, l2)
l1试图提供大量FP原语
purrr
的zip版本称为
transpose()


L1我不认为这正是您想要的,但如果是等长向量,您可以符合数组,然后对任意方向使用拆分:

l <- list(c(1, 9), c(2, 8), c(3, 7))

m <- do.call(rbind, l)

split(m, row(m))
split(m, col(m))

## > split(m, row(m))
## $`1`
## [1] 1 9
## 
## $`2`
## [1] 2 8
## 
## $`3`
## [1] 3 7


## > split(m, col(m))
## $`1`
## [1] 1 2 3
## 
## $`2`
## [1] 9 8 7
l拆分(m,col(m))
## $`1`
## [1] 1 2 3
## 
## $`2`
## [1] 9 8 7

Map(c,l1,l2)
Map(c,tuple1,tuple2,tuple3)
我认为-你的R示例有点混乱。@最近的邮件谢谢,我相应地更新了这个问题。如果你满意的话,我想答案是
Map
函数。请随意回答下面的问题:-)尼斯在一个月前的一个视频中看到了这一点,但记不起它所在的软件包了+1如果我理解正确(可疑),我想应该是
l%>%transpose()%%>%simplify\u all()
tuple1 <- list(1,2)
tuple2 <- list(2,3)
tuple3 <- list(3,4)
l <- Map(c, tuple1, tuple2, tuple3)
 L1 <- list(as.list(1:3),as.list(9:7))
 library(purrr)
 (L2 <- transpose(L1))
## List of 3
##  $ :List of 2
##   ..$ : int 1
##   ..$ : int 9
##  $ :List of 2
##   ..$ : int 2
##   ..$ : int 8
##  $ :List of 2
##   ..$ : int 3
##   ..$ : int 7
identical(transpose(L2),L1)  ## TRUE
l <- list(c(1, 9), c(2, 8), c(3, 7))

m <- do.call(rbind, l)

split(m, row(m))
split(m, col(m))

## > split(m, row(m))
## $`1`
## [1] 1 9
## 
## $`2`
## [1] 2 8
## 
## $`3`
## [1] 3 7


## > split(m, col(m))
## $`1`
## [1] 1 2 3
## 
## $`2`
## [1] 9 8 7