【问题标题】:Separate items in list with a comma in R在R中用逗号分隔列表中的项目
【发布时间】:2021-12-31 02:42:41
【问题描述】:

我正在尝试用逗号分隔列表中的每个值。例如,我正在寻找 'item1','item2' 而不是 'item1''item2'。

这是我正在使用的:

combos <- lapply(2:4, function(x) combn(c("item1","item2","item3","item4"), x, simplify = FALSE))
combos <- unlist(combos, recursive = FALSE)

谢谢!

【问题讨论】:

  • 试试lapply(combos, toString)
  • 谢谢@akrun!这正是我想要的。

标签: r list


【解决方案1】:

我们用lapplypaste循环listtoString

lapply(combos, toString)

【讨论】:

  • ,@akrun。这将如何与Map(paste(., collapse = ","), combos) 一起使用?
  • @TarJae 你可以使用Map(paste, combos, MoreArgs = list(collapse =",")) 或明确的lambda 表达式Map(function(x) paste(x, collapse=","), combos)
  • 现在MoreArgs。谢谢大师!
猜你喜欢
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多