Exporting a csv file to Excel using R

Exporting a csv file to Excel using R

2015, Jan 10    

.csv to .xlsx using R

In many occasions, you don't really have to use R to open .csv files on Excel. You can just open a csv file on Excel, and it works!

You can do the same by using several commands of R, too. And it magically solves some encoding issues. I was trying to open a csv file that has Korean texts and encoded in UTF-8 on Excel(ANSI) in Windows. Notepad ++ did change the encoding type, but the file didn't look neat enough on Excel... like this

this doesn't look alright My twitter activities from analytics.twitter.com

xlsx library on R

By using "xlsx" library on R, you can easily turn a .csv file to .xlsx file.
1. open R and import "xlsx" library.
(If not installed) > install.packages("xlsx")
> library("xlsx")

2. read in the csv file and designate it to "doc" variable.
> doc <- read.csv("the_csv_file_you_want.csv", encoding="UTF-8")

3. write an xlsx file.
> write.xlsx(doc, "new_name_of_the_file.xlsx")

4. open the file on Excel!
it works!

this look alright Now it looks alright!