My Coding > Software > R > R: Exel spreadsheet

R: Exel spreadsheet

Preparation R for using Exel spreadsheets

R can read exel spreadsheets . To read exel files it is necessary to use function read_exel(filename)

Before this function will be available in R, it is necessary to install proper dependencies for linux:


sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev

and also install this package with the R environment


install.packages("tidyverse")
install.packages("writexl")

Reading from Exel

After these preparation it is possible to read Exel spreadsheets into R structure with command read_exel(). After reading – always check the structure with function str()


library(readxl)

eg <- read_exel(filename) # This will contain data and exel spreadsheet parameters
df = <- as.data.frame(eg) # convert into additional data.frame
eg2 <- read_exel(filename, sheet=2) # read second sheet from exel spreadsheet

Exporting to Exel

Let’s imagine, we already have some data.frame df1 and df2 in R.


library(writexl)

write_xlsx(df1, "path/filename1.xlsx" # write Exel file
write_xlsx(list(page1=df1, page2=df2), "path/filename2.xlsx" # write Exel file with two pages


Published: 2021-11-11 03:07:09
Updated: 2021-11-11 03:34:13

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.