- Prepare a text file (.txt or .csv) for import into R
- Import the data using the function
- Recognize and fix the most common problems that cause errors when importing data
Data and R Code Files Section
The R code file and data files for this lesson can be found on the Essential R - Notes on learning R page.
The following data files should be in the "Data" folder in your "Essential R" folder; or you can save them to your working directory.
W101-2010.xls (Excel file) and W101-2010.csv (text file made from the Excel file). The example text files are: Ex1.txt, Ex2.txt, Ex3.txt, and Ex3.csv. The data file required for Exercise 2 is here: StatesData.xls.
readr. This replaces
read_csv(). This will read in your data but may convert some of the variables differently than
read.csv()would do. (
read_csv()will create a "tibble", which is subtly different from a data.frame). My suggestion to avoid the confusion is to edit the code that rstudio wrote in your console - replace
read.csvand rerun the code - you should be fine.