Make a list from ls(pattern=“”) [R]

前端 未结 1 1768
渐次进展
渐次进展 2021-01-03 07:26

The ls(pattern=\"\") function is very useful for me, since my list of objects seem to keep growing and growing. I am curious if this feature can be more useful.

相关标签:
1条回答
  • 2021-01-03 08:13

    A couple of issues:

    1) The . in ".c" gets ignored, you need to "escape" it:

    ls(pattern="\\.c")
    

    Otherwise it will return all objects with c regardless of having a period.

    2) ls returns names of objects as character. To get the value of an object based on its name you need the function get:

    lapply(ls(pattern="\\.c"), get)
    

    3) As joran mentioned in the comments, it's much better to keep objects associated with each other in lists:

    List.c = list(a.c=1, b.c=2, c.c=3, d.c=4)
    
    0 讨论(0)
提交回复
热议问题