【问题标题】:search hierarchical list in R在 R 中搜索分层列表
【发布时间】:2018-10-30 20:57:48
【问题描述】:

我有一长串由var_label 函数在labelled 包中生成的变量标签,如下所示:

list(prtclcie = "Which party feel closer to, Ireland", dweight = "Design weight", 
    edlvfdit = "Father's highest level of education, Italy", 
    edlvpdru = "Partner's highest level of education, Russian Federation", 
    edlvdpt = "Highest level of education, Portugal", icwhct = "Have a set 'basic' or contracted number of hours", 
    uemp3m = "Ever unemployed and seeking work for a period more than three months", 
    icomdng = "Interviewer code, one/more than one doing last 7 days", 
    edlvfenl = "Father's highest level of education, Netherlands", 
    prtvtdfi = "Party voted for in last national election, Finland")

我想找到一个命令来根据关键字搜索这个列表,输出是列名,stg。比如prtclcieedlvfdit等等。

我尝试过使用grep("keyword", list),但这只会给出“命中”的行号,而不是列表结构中的上层名称。

【问题讨论】:

    标签: r data-management


    【解决方案1】:

    使用value=TRUE 返回值而不仅仅是索引

    grep("educ", list, value=TRUE)
    

    如果您只想要列表中的名称,请使用

    names(grep("educ", list, value=TRUE))
    

    【讨论】:

      猜你喜欢
      • 2011-05-10
      • 2017-04-04
      • 2022-01-24
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多