如何將字串串列轉換為串列a串列b
a = list('A', 'B', 'C')
并轉換為
b = list(list('A'), list('B'), list('C'))
使用 R? 謝謝。
uj5u.com熱心網友回復:
將函式list應用于串列a:
lapply(a, list)
[[1]]
[[1]][[1]]
[1] "A"
[[2]]
[[2]][[1]]
[1] "B"
[[3]]
[[3]][[1]]
[1] "C"
uj5u.com熱心網友回復:
一個可能的解決方案,使用purrr::map:
library(tidyverse)
a = list('A', 'B', 'C')
b = list(list('A'), list('B'), list('C'))
a %>% map( ~ list(.x)) %>% identical(b)
#> [1] TRUE
a %>% map( ~ list(.x))
#> [[1]]
#> [[1]][[1]]
#> [1] "A"
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [1] "B"
#>
#>
#> [[3]]
#> [[3]][[1]]
#> [1] "C"
或者簡單地說:
map(a, list)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/419773.html
標籤:
上一篇:無法創建物體框架代碼優先遷移
