如何将包含中英文单词的数据框导出到 csv 文件?当我正常导出时,甚至当我使用UTF-8编码导出时,显示的中文单词如下所示:
(<U+6709>)<U+307F><U+3064><U+3044><U+5712>
这是我要导出的 R 脚本:
library(xlsx)
write.csv(df_final,file = "./df_final.csv",
row.names=FALSE,
fileEncoding = "UTF-8")
一种选择是write_excel_csv
从readr
包中使用。它似乎比处理 UTF8 更好write.csv
。这对我有用:
chinese = c("狗", "猫")
Encoding(chinese) = "UTF-8"
english = c("dog", "cat")
df_final = data.frame(chinese, english)
Encoding(df_final$chinese) = "UTF-8"
library(readr)
write_excel_csv(df_final, file = './df_final.csv')