Read Excel File in R (Example) | xlsx, xls, read_excel, readxl, & openxlsx | Multiple Files & Sheets

preview_player
Показать описание
R code of this video:

data(iris) # Load iris data to RStudio
head(iris) # Print first 6 rows of iris

library("xlsx") # Load xlsx R package to RStudio

setwd("C:/Users/Joach/Desktop/my directory") # Set working directory

sheetIndex = 1)

library("readxl") # Load readxl R package to RStudio

library("openxlsx") # Load openxlsx R package to RStudio

data(mtcars) # Load mtcars data to RStudio
head(mtcars) # Print first 6 rows of mtcars

append = TRUE, # Specify that data gets appended
sheetName = "mtcars")

sheetName = "mtcars")

all_file_names # Print list of xlsx files in directory

data_list <- lapply(all_file_names, read_excel) # Read multiple excel files

sheetIndex = 1)

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

This is a great video on a pretty confusing (and ever-changing) topic.
I would like to add that I personally use readxl::read_excel to bring files in because I like tibbles, and openxlsx::write.xlsx to write them out. The 'xlsx' package requires Java and has been a pain to deal with across different computers, whereas the other two packages don't. Also, 'readxl' has xls and xlsx specific functions in the read_*, but read_excel automatically checks the file extension.

douglaspage
Автор

I agree with previous message. I get a ton of error messages with write.xlsx (and actually just trying to load in the library itself).

haraldurkarlsson
Автор

Also when I am reading in Excel files I simply save them as csv and then read them into R. Gives me fewer head aches.

haraldurkarlsson
Автор

Yes, but what happens with read.xlsx2() and write.xlsx2()? Do you have any examples? in specific of Java problem

joseoscardelgadobautista