我想将csv文件转换为excel。
从Internet上的搜索中,我发现最好的建议是使用库(xlsx)并使用write.xlsx(..)将数据框写入excel文件。
但是,当我尝试加载并使用xlsx库并使用它时,会收到以下消息:
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/Ban/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
LoadLibrary failure: Could not find the specified mode. unit.
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以将csv转换为excel,还是有人遇到过以前的问题?
您可以在rio中执行此操作,而无需Java依赖项。它调用openxlsx包。
install_github("leeper/rio")
library("rio")
# create an example CSV
export(mtcars, "mtcars.csv")
# convert the CSV to Excel (.xlsx)
convert("mtcars.csv", "mtcars.xlsx")
Run Code Online (Sandbox Code Playgroud)
如果您想直接使用openxlsx进行此操作,则可以运行以下命令:
library("openxlsx")
write.xlsx(read.csv("mtcars.csv"), "mtcars.xlsx")
Run Code Online (Sandbox Code Playgroud)
完全披露:我是rio的作者。