🤖
R for SEO
  • Using R for SEO, What to expect?
  • Getting started
  • What is R? What is SEO?
  • About this Book
  • Crawl and extract data
    • What's crawling and why is it useful?
    • Download and check XML sitemaps using R'
    • Crawling with rvest
    • Website Crawling and SEO extraction with Rcrawler
    • Perform automatic browser tests with RSelenium
  • Grabbing data from APIs
    • Grab Google Suggest Search Queries using R'
    • Grab Google Analytics Data x
    • Grab keywords search volume from DataForSeo API using R'
    • Grab Google Rankings from VALUE SERP API using R'
    • Classify SEO Keywords using GPT-3 & R'
    • Grab Google Search Console Data x
    • Grab 'ahrefs' API data x
    • Grab Google Custom search API Data x
    • Send requests to the Google Indexing API using googleAuthR
    • other APIs x
  • Export and read Data
    • Send and read SEO data to Excel/CSV
    • Send your data by email using gmail API
    • Send and read SEO data to Google Sheet x
  • data wrangling & analysis
    • Join Crawl data with Google Analytics Data
    • Count words, n-grams, shingles x
    • Hunt down keyword cannibalization
    • Duplicate content analysis x
    • Compute ‘Internal Page Rank’
    • SEO traffic Forecast x
    • URLs categorization
    • Track SEO active pages percentage over time x
  • Data Viz
    • Why Data visualisation is important? x
    • Use Esquisse to create plots quickly
  • Explore data with rPivotTable
  • Resources
    • Launch an R script using github actions
    • Types / Class & packages x
    • SEO & R People x
    • Execute R code online
    • useful SEO XPath's & CSS selectors X
Powered by GitBook
On this page
  • Read your data from a CSV
  • Export your data into a CSV
  • Read an excel
  • Export your data into an excel file
  • Import and merge a batch of CSV files

Was this helpful?

  1. Export and read Data

Send and read SEO data to Excel/CSV

CSV and Excel file remain one of amongst the most well-used file formats for exchange data.

Read your data from a CSV

#setup where to read the file
setwd("~/Desktop")
# en write the file
test <- read.csv(df, "data.csv")

Export your data into a CSV

assuming your data is store inside df var, fairly simple:

#setup where to write the file
setwd("~/Desktop")
# en write the file
write.csv(df, "data.csv")

Read an excel

# the file.choose() will prompte a file selector
# the 1 say we want to load the first tab
test <- xlsx::read.xlsx(file.choose(),1)

Export your data into an excel file

A little bit more complex, we’ll use the ‘xlsx’ package

#setup where to write the file
setwd("~/Desktop")
 
# if the package is not instal yet, run this  
# install.packages("xlsx")
 
# Loading the package 
library(xlsx)
 
# we write the file 
write.xlsx(df, "data.xlsx")

A few more tips for you:

I’ll like to use the sheetName option to explicitly name the tab. The default name is “Sheet1”. Quite useful to have a record of when the file has been generated for example. Replace last instruction what follows and you’ll be able to know.

write.xlsx(df, "data.xlsx", sheetName=format(Sys.Date(), "%d %b %Y"))

Another good one that I like is to send the excel file to a Shared folder directly. Replace first instruction by

setwd("/Users/me/Dropbox/Public")

Of course, replace the file path with yours.

Import and merge a batch of CSV files

Aggregate several CSV files into one using file name as a column

library(plyr)
library(readr)
library(purrr)

# add the path where the csv's are located
setwd("./Downloads/test/")

# list csv files inside the directory
# for each: import the csv (read.csv function)
# add filename as a column
# and merge

Tbl <- list.files(path = "./",
                  pattern="*.csv", 
                  full.names = T) %>% 
                  map_df(function(x) read_csv(x, col_types = cols(.default = "c")) %>%
                  mutate(filename=gsub(".csv","",basename(x)))) 


View(Tbl)
Previousother APIs xNextSend your data by email using gmail API

Last updated 3 years ago

Was this helpful?