我正在尋找諸如函數式編程語言(例如Haskell,Scala)中的zip/unzip函數。R中的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只給我壓縮/解壓縮文件的結果。)
'地圖(C,L1, l2)'和'Map(c,tuple1,tuple2,tuple3)'我想 - 你的R例子有點混亂。 – thelatemail
@thelatemail謝謝,我相應地更新了問題。 –
嗯,我想如果你滿意的話,答案就是'Map'函數。請隨時回答您自己的問題:-) – thelatemail