createWorkbook(type = ext)中的错误:R中的未知格式数据

Posted

技术标签:

【中文标题】createWorkbook(type = ext)中的错误:R中的未知格式数据【英文标题】:Error in createWorkbook(type = ext) : Unknown format Data in R 【发布时间】:2021-04-19 20:44:49 【问题描述】:

我使用 R 制作了一个由 9 列组成的数据集,其中 2 列是字符,其余的是数字,为此我使用了命令 data.frame 我想将数据集保存在我的计算机中的 excel 文件中,所以我使用以下代码:

write.xlsx(new_data, file)

file 是我要保存的目的地。我曾多次尝试过该命令,它运行良好,但这次我收到一条错误消息:

Error in createWorkbook(type = ext) : Unknown format Data

我不知道如何解决这个问题。我已经下载了相应的包来使用该命令,并且我也在使用该库,所以这不是问题。

部分数据集如下所示:

structure(list(Year = c(2020, 2020, 2020, 2020, 2020, 2020, 2020, 
2020, 2020, 2020, 2020, 2020, 2021, 2021, 2021, 2020, 2020, 2020, 
2020, 2020), Month = c("April", "August", "December", "February", 
"January", "July", "June", "March", "May", "November", "October", 
"September", "February", "January", "March", "April", "August", 
"December", "February", "January"), Country = c("Austria", "Austria", 
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria", 
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria", 
"Austria", "Belgium", "Belgium", "Belgium", "Belgium", "Belgium"
), Yearly_Avg = c(16.8744280559468, 16.5742978691062, 19.7582603823048, 
20.0995113726207, 22.159638908606, 16.3921228601795, 16.0600580144822, 
18.0429069983406, 16.1335324637284, 19.3313366495739, 18.1576751355617, 
17.7576825704506, 20.5023364228561, 20.4796477705191, 21.8839427966824, 
17.5093947635307, 16.8244128304848, 18.2986763058834, 17.6349268331471, 
19.3710576260764), Monthly_Avg = c(17.5439477479378, 15.9341820502547, 
17.530722007165, 15.8389913543081, 20.5105660799249, 16.2600932619789, 
9.87181304501773, 17.1856966348436, 15.0898542839449, 18.3777431503772, 
15.8249359315534, 16.3004100301265, 20.3146212543137, 18.642219655174, 
20.9761885859812, 19.8377753973291, 16.8487709028363, 15.2106954951857, 
15.5311747851574, 17.1658612678814), Weekly_Avg= c(7.10475853031207, 
6.11148507770456, 7.85609336456891, 6.55222253962218, 9.43989731346756, 
5.81589613640666, 5.19628464098288, 7.22802554102707, 5.80143233950403, 
8.13800967670196, 6.48376157165925, 6.32095532711856, 8.68986433237802, 
8.39290625115118, 9.15735048128797, 15.9512610874645, 11.3482807319524, 
12.7782717870906, 11.3638932656897, 14.7351012362691), Price_1 = c(28.4611003454724, 
35.6054984184222, 39.2081812263157, 0, 0, 26.230988052438, 27.2078733696025, 
30.2269874357209, 22.9303758469904, 52.7661622570557, 36.3581735319494, 
32.9769837451705, 18.4098585648499, 37.7051687645876, NA, 36.1320055593011, 
41.0302230604013, 38.583355656882, 5.83773044716594, 0), Price_2 = c(18.8790737297885, 
6.22257626807137, 26.4138764718301, 0, 0, 3.46573590279973, 11.3777927909787, 
6.95654544315157, 11.8168745098859, 28.9183654237345, 15.3226286604391, 
9.44145209293957, 11.3328054829311, 23.6779310397014, NA, 29.4627378650933, 
17.784291897211, 25.8144436031916, 0, 0), Price_3 = c(5.1, 5.6, 
6.1, 4.9, 4.3, 5.9, 6.2, 4.9, 5.7, 5.2, 5.2, 5.6, NA, 5.5, NA, 
4.9, 6.6, 5.8, 5.1, 5.2)), row.names = c(NA, 20L), class = "data.frame")

我使用的代码是

new_data <- data.frame("Year" = data1$Year, "Month"= data1$Month, "Country" = data1$Country, "Week" = data1$Weekly_Avg, "Monthly_Avg" = Monthly_Avg, "Yearly_Avg" = Yearly_Avh, "Price1" = data2$Price_1, "Price2" = data2$Price_2, "Price3" = data2$Price_3)

write.xlsx(new_data, "C:/Users/MK/Documents/Project/Data")

我从不同的数据集中获取这些数据,并将它们放在一起后,它的格式为 grouped_df。我尝试将其设置为如上所示的数据框,但我仍然无法将其保存在 excel 文件中。

任何帮助将不胜感激。或者关于如何在我的计算机上保存该数据集的任何其他想法。

提前致谢!

【问题讨论】:

能否请您提供数据集和使用的代码? minimal reproducible example 提供有用的指导,说明问题中最好包含的内容。 我只是上传了更多信息。我希望有用。谢谢 您好,您可以使用dput(new_data) 将数据粘贴到问题中,以便轻松复制吗?或 dput(head(new_data, 20)) 如果数据集很大;检查示例数据是否会导致错误,否则将无济于事。 试试write.xlsx(new_data, "C:/Users/MK/Documents/Project/Data.xlsx") 所有文件夹都是在保存之前创建的吗?我运行write.xlsx(new_data, "Data.xlsx") 将文件保存在 r 项目目录中没问题。我不确定xlsx 是否还没有创建目录路径。 【参考方案1】:

问题出在输出名称上。需要扩展名“xlsx”。

write.xlsx(new_data, "C:/Users/MK/Documents/Project/Data.xlsx")

我遇到了同样的问题,解决了。

【讨论】:

非常感谢!【参考方案2】:

如前所述,需要“.xlsx”扩展名。但是,如果您已经定义了路径,则无需在命令中将其写出来:

write.xlsx(new_data, "Data.xlsx")

如果你想把它放在它自己的文件夹中,你可以简单地在名称之前添加它(即文件夹名称“新数据”):

write.xlsx(new_data, "New Data/Data.xlsx")

【讨论】:

以上是关于createWorkbook(type = ext)中的错误:R中的未知格式数据的主要内容,如果未能解决你的问题,请参考以下文章

CentOS挂载mount: unknown filesystem type ‘ext4‘错误

ext4.0 二级联动

extjs extjs5 Ext.grid.Panel 搜索示例

ExtJs之 Ext.JSON

无法在Ext.draw.Container构造函数中添加精灵

ExtJs之Ext.core.Element