【问题标题】:split list and keep first value in R [duplicate]拆分列表并将第一个值保留在 R [重复]
【发布时间】:2019-09-30 21:07:29
【问题描述】:

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

[[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"

【问题讨论】:

标签: r


【解决方案1】:

一个选项是lapply

lapply(lst1, `[`, 1)

或者使用firstmap

library(purrr)
map(lst1, first)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 2014-04-01
    • 2018-06-25
    • 2016-03-20
    • 2017-12-24
    • 2018-09-07
    相关资源
    最近更新 更多