【发布时间】:2016-11-29 10:19:43
【问题描述】:
我正在寻找函数式编程语言(例如 Haskell、Scala)中的 zip/unzip 等函数。
Examples from the Haskell reference。邮编:
Input: zip [1,2,3] [9,8,7]
Output: [(1,9),(2,8),(3,7)]
解压:
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)
解压:
tuple1 <- list(1,2)
tuple2 <- list(2,3)
tuple3 <- list(3,4)
l <- Map(c, tuple1, tuple2, tuple3)
R 中是否有实现这些方法的内置解决方案/库? (FP 函数往往有很多名称 - 搜索 zip/unzip 和 R 只给我压缩/解压缩文件的结果。)
【问题讨论】:
-
Map(c, l1, l2)和Map(c, tuple1, tuple2, tuple3)我认为 - 你的 R 示例有点令人困惑。 -
@thelatemail 谢谢,我相应地更新了问题。
-
好吧,我认为答案是
Map函数,如果你满意的话。随意在下面回答您自己的问题:-)