as.data.frame.default(x[[i]], optional = TRUE) 中的错误:无法将 class ‘"formula"’ 强制转换为 data.frame

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

我有 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

请帮忙解决这个问题。

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

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