Types of Input in R Programming Language

Rumman Ansari   Software Engineer   2023-03-24   6038 Share
☰ Table of Contents

Table of Content:


Much of the data you use in R will be data you input from other sources where you have been storing your experimental data, such as excel spreadsheets. Learning to correctly read in this data is important and will allow you to use R on data from any of the most common types of files. You will hopefully find this process quick and intuitive.

In R, we can read data from files stored outside the R environment. We can also write data into files which will be stored and accessed by the operating system. R can read and write into various file formats like csv, excel, xml etc.

Types of Input

There are two main types of data that you will read into R:

spreadsheet type data and data that is already in R object form, but saved to its own file. Spreadsheet type data is read in as ?delineated? files. Delineated files mean that there is some standard separator to tell R how to separate cells in a table. For example, a comma delineated file uses commas between cells:

thing1, thing2, thing3, thing4, thing5
The above would be read in as:

[1] "thing1" "thing2" "thing3" "thing4" "thing5"

If you want to import the data you have saved in an Excel spreadsheet into R, the most painless method is to save the excel spreadsheet as a comma-separated file .csv (it‘s under Save As > Other Formats inExcel, or you can simply use Save As and then type the .csv extension) and then simply follow the instructions below for importing a comma delineated file into R.

There are, however, several main methods for importing spreadsheet format data. The method that you use depends on the format that you save your data into before importing the data into R. As mentioned above, I prefer using the .csv format, but other formats such as delineation by semicolon and tab are possible and you may encounter them and have to use one of the other methods presented in subsequent tutorial.