【问题标题】:Create an ellipsis (...) from list从列表中创建省略号 (...)
【发布时间】:2013-09-03 22:43:32
【问题描述】:

是否可以从列表中创建省略号 (...)?我们的想法是能够执行以下操作:

mylist <- list(a=1,b=2,c=3)
myellipsis <- create_ellipsis(mylist)
print(switch('a', myellipsis)) # output 1

【问题讨论】:

    标签: r


    【解决方案1】:

    你想要do.call,它可以将列表的内容传递给函数...参数:

    do.call(function(...) print(switch('a', ...)), mylist)
    

    【讨论】:

    • 太棒了,知道它看起来很简单:-)。谢谢!
    • 当您的函数指定其他参数时,按照this answer 使用c( arg, arg, ..., myList ) 连接它们的预期(覆盖)值,例如:do.call(function(b=4, ...) print(switch('b', ...)), c(4, myList))
    猜你喜欢
    • 1970-01-01
    • 2019-04-04
    • 2017-12-28
    • 1970-01-01
    • 2015-11-21
    • 2011-03-09
    • 2013-06-14
    • 1970-01-01
    • 2020-01-20
    相关资源
    最近更新 更多