Nov 13, 2019 in R Language

Q: Import Data into R: Read CSV, Excel, SPSS, Stata, SAS Files

1 Answer

Nov 13, 2019

Read CSV

One of the most widely data store is the .csv (comma-separated values) file formats. R loads an array of libraries during the start-up, including the utils package. This package is convenient to open csv files combined with the reading.csv() function. Here is the syntax for read.csv

read.csv(file, header = TRUE, sep = ",")

Read Excel files

Excel files are very popular among data analysts. Spreadsheets are easy to work with and flexible. R is equipped with a library readxl to import Excel spreadsheet.

Use this code


Read sas

For our example, we are going to use the admission dataset from IDRE.

PATH_sas <- ''
df <- read_sas(PATH_sas)


For STATA data files you can use read_dta(). We use exactly the same dataset but store in .dta file.

PATH_stata <- ''
df <- read_dta(PATH_stata)


We use the read_sav()function to open a SPSS file. The file extension ".sav"

PATH_spss <- ''
df <- read_sav(PATH_spss)
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Jul 28, 2019 in R Language
Nov 4, 2019 in R Language
Jul 28, 2019 in R Language