Author: Žaneta Vaníčková

This article describes how to simply load data from Excel table to R script environment.

We´re going to use these two commands:

We are getting the data for R analysis very often in .xlsx files. There are many packages enabling us to export / import to / from Excel to R. But, anyway, getting data from Excel isn´t too easy usually. Some users are saving the data from Excel to .csv and importing after.
So in this tutorial, we will show how to get the data from Excel easily – using the Windows clipboard.
Let´s start.
You can use any Excel file. Select all data you want to copy and copy it (Ctrl + C).

Open R studio. Now you need to paste. This can be done by this command, importing data from Windows clipboard:

Head() function shows first few rows only.

To see complete data, write this instead:

Columns in Excel are separated by tab (\t). The readClipboard() function itself can´t work with delimiter, it is mostly mused for quick import of row data. So to load of data the read.table() function should be used.

Explanation of input parameters of read.table() function:

  • file = ‘clipboard’ - the source of data is the clipboard
  • sep = “\t” – tab is used as delimiter
  • header = TRUE – the first row contains headers of columns
  • stringsAsFactors = FALSE – we´re not using “factor” datatype

Leave a Reply

Your email address will not be published.

*

clear formPost comment