Data comes in various formats. Most of the data available online can be downloaded in the form of text documents (
.txt extension) or as comma-separated values (
.csv). We also encounter data in the tab-delimited format, XLS, HTML, JSON, XML, and so on. If you are interested in working with data, either in JSON or XML, refer to the recipe Constructing a bar plot using XML in R in Chapter 10, Creating Applications in R.
In order to import a CSV file in R, we can use the
test = read.csv("raw.csv", sep = ",", header = TRUE)
read.table() function allows us to import data with different separators and formats. Following are some of the methods used to import data in R: