拆分列表并将第一个值保留在 R 中



在下面的列表中,我想保留每个项目的第一个值。

[[1]]
[1] "Avatar" "xe6"  
[[2]]
[1] "Pirates of the Caribbean: At World's End" "xe6"                                    
[[3]]
[1] "Spectre" "xe6"   

看起来像

[[1]]
[1] "Avatar" 
[[2]]
[1] "Pirates of the Caribbean: At World's End"                                 
[[3]]
[1] "Spectre"

一个选项是lapply

lapply(lst1, `[`, 1)

或者将firstmap一起使用

library(purrr)
map(lst1, first)

相关内容

最新更新