0

How can I export a data frame that has both English and Chinese words to a csv file? When I normally export it or even when I use a UTF-8 encoding to export the Chinese words are displayed as the following example:

(<U+6709>)<U+307F><U+3064><U+3044><U+5712>

This is my R script to export:

library(xlsx)
write.csv(df_final,file = "./df_final.csv",
          row.names=FALSE,
          fileEncoding = "UTF-8")
Ibo
  • 4,081
  • 6
  • 45
  • 65

1 Answers1

2

One option would be to use write_excel_csv from the readr package. It seems to handle UTF8 better than write.csv. This worked for me:

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')
G5W
  • 36,531
  • 10
  • 47
  • 80