Read and import different data files in R: Excel, CSV, SPSS, txt, url

Steps to Read and import different data files in R

Using point and click option without R codes

1. Click on file (Top left corner)

2. Click on Import datasets

3. If you are importing,
• .txt file in R, then click on “from Text(base)”
• .csv file (comma separated values) in R, then click on “from Text(readr)”
• Excel file in R, then click on “Excel”
• SPSS file in R, then click on “SPSS
• SAS file in R, then click on “SAS”

4. This will open up prompt window, R will require an additional package names “readr” for importing this data set. R will ask “Do you want to install these packages”.

5. Click “yes”

6. Click on “Browse” (Top right)

7. Identify the location of the file which you would like to import

8. As soon as you identify the location, this will give you a data preview.

9. If the data preview is correct, then click on “Import”


Steps to read and import data with R codes

1. Reading data from .csv file (comma separated values)

            Install the “readr” package


        Titanic <- read_csv("D:/2.0 Titanic/my_solution_tree.csv")

2. Reading data from Excel file


  Recall readxl package for reading excel files 


store_visits <- read_excel("D:/store visits.xlsx")


3. Reading data from Text file


        text <- read.table("C:/Users/Ateeque Shaikh/Desktop/text.txt", header=TRUE, quote="\"")


               text – name of the file

               read.table – command for reading the text file

               “” – within double quotes is the path where your is located

               Header = TRUE – takes the header as the name

               Quote = “” – considers the data in double quotes


4. Reading data from SPSS file

      # Recall library haven – for import and export of SPSS Stata and SAS files



Train <- read_sav("D:/Train.sav")



   iris <- read.csv(url(""), header = FALSE)

     # Assigning names to the columns/ variables in the url

   names(iris) <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")


Leave a Reply

Your email address will not be published. Required fields are marked *