【问题标题】:Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ‘"formula"’ to a data.frameas.data.frame.default(x[[i]], optional = TRUE) 中的错误:无法将“公式”类强制转换为 data.frame
【发布时间】:2020-01-16 13:57:20
【问题描述】:

我有 4 个数据框,我正在尝试将 4 个数据框导出到同一个工作簿中

list_of_dataframes <- list(
                        "Scoring" ~ store_score,
                        "Store" ~ store_ware,
                        "Brand" ~ brand_ware,
                        "Article" ~ article_ware
                      )

openxlsx::write.xlsx(list_of_dataframes, "filename.xlsx")

Error : Error in as.data.frame.default(x[[i]], optional = TRUE) :    cannot coerce class ‘"formula"’ to a data.frame

请帮助解决这个问题。

【问题讨论】:

  • 您的list_of_dataframes 显然不是data.frames 列表,而是公式列表。你看过print(list_of_dataframes )吗?

标签: r openxlsx


【解决方案1】:

如果您的目标是列出 data.frames,那么您应该使用 = 而不是 ~

list_of_dataframes <- list(
                        "Scoring" = store_score,
                        "Store" = store_ware,
                        "Brand" = brand_ware,
                        "Article" = article_ware
                      )

【讨论】:

  • 而且不需要引用名字……毕竟,你也没有写"list_of_dataframes" &lt;- …,尽管你可以。
猜你喜欢
  • 1970-01-01
  • 2021-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多