How To Import .XLSX / .CSV & .TXT Files In R!

Manpreet Singh
2 min readJan 17, 2021

R is one of my favorite languages ever, and the backbone of R is data manipulation, so let’s go ahead and figure out how to import .xlsx / .csv and .txt files into your R session! If you don’t have R or RStudio installed on your machine please follow this article which shows exactly how to do it!

Importing .xlsx Files

In order to import .xlsx files we need to make sure we have a .xlsx files on our machine, once we locate that file we want to note the specific file directory. Once noted, let’s go into our R console and install the “readxl” package by using the following script:

Once installed, let’s go ahead and read in the package by using the following line:

#IMPORT THIS PACKAGE
library(readxl)

Awesome! Next up all we have to do is copy and paste the following code:

#READING IN THE FILE
testdf <- read_xlsx("DELETE THIS TEXT AND ADD IN YOUR FILE DIRECTORY", sheet = 1)

In this line of code we are setting up a variable name “testdf”, we then go ahead and read in the xlsx file by using the “read_xlsx” function, we then take our file directory of our xlsx file and paste it in between the 2 quotes. The “sheet” function specifies which sheet within the Excel file we want to read in, the ending code for this…

--

--