It’s time for another post about R.
I’ll admit, these days most of my work is done in R. But, I still love using Excel, and I really do enjoy teaching and blogging about it.
Subscribe to my newsletter for your free ebook, “The Beginner’s Guide to Getting Hired with Excel.”
Let’s say you need to do some data analysis or manipulation in R but want to bring it back into Excel for visualization or distribution to colleagues.
In the past, I may have used write.csv() to export the file to a csv, then gone to Excel to open.
That’s still a solid option, but I really like this XLView() function from the DescTools() library. Get this function running with the below packages…
In this demonstration, I am using the famous iris dataset (download here)
Like magic, something like the below workbook should open in Excel. From there, simply head to Data | Text to Columns and split the columns as semicolon-delimited. All about XLView()
Like with any function in R, learn about the arguments it takes with the str() function. Try str(XLView):
XLView has three optional arguments: whether you want column names (i.e. header names), row names (i.e. an index/ID number as your first column), and how to label missing values (usually as a blank or “NA.”) By default, XLView will give you column but not row names, and label missing values as blanks or ” “.
I imagine this is what the majority of users would want. Still, it’s good to know the options.
This is a great function for integrating R and Excel. I like that it opens Excel for you on command unlike write.csv(). It is also relatively easy to download, unlike some competing Excel/R packages.
Did this post help you? Please like, comment and share. Got questions about R, Excel or their colliding worlds? Leave a comment below.
Leave a Reply