Skip to content

This repository contains R scripts to connect to a PostgreSQL database, execute queries, and analyse data using “DBI”, “RPostgres”, and “dplyr”. Perfect for integrating R with PostgreSQL for efficient data analysis.

License

Notifications You must be signed in to change notification settings

linuschirchir/Analysing-PostgreSQL-Data-in-R

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Analysing PostgreSQL Data in R

This repository contains code and instructions for connecting to a PostgreSQL database and performing data analysis using R, as explained in the article by Linus Chirchir.

Table of Contents

Introduction

This project demonstrates how to connect to a PostgreSQL database from R and perform data analysis using popular R packages like DBI, RPostgres, and dplyr. The repository includes example scripts that guide you through querying data and conducting basic analysis, making it a useful resource for data scientists and analysts who work with PostgreSQL.

Prerequisites

Before you begin, ensure you have the following installed:

  • R (version 3.6 or later)
  • RStudio (optional, but recommended for ease of use)
  • PostgreSQL database (local or remote)
  • Necessary R packages: DBI, RPostgres, dplyr

Installation

First, install the required R packages:

install.packages(c("DBI", "RPostgres", "dplyr"))

Fork the repository:

Clone your forked repository to your local machine:

git clone https://github.com/<your-GitHub-username>/Analysing-PostgreSQL-Data-in-R.git
cd Analysing-PostgreSQL-Data-in-R

Connecting to PostgreSQL

The main script for connecting to the PostgreSQL database is included in the connect_to_db.R file. You can run this script in your R environment:

source("connect_to_db.R")

This script sets up a connection to your PostgreSQL database, allowing you to execute SQL queries directly from R.

Querying and Analysing Data

Once connected, you can use the query_and_analyse.R script to retrieve and analyse data. This script demonstrates how to:

  • Write and execute SQL queries in R
  • Manipulate and analyse the retrieved data using dplyr
  • Visualise results with basic plotting functions

Run the script as follows:

source("query_and_analyse.R")

Customisation

Feel free to customise the scripts to suit your needs:

  • SQL Queries: Modify the SQL queries in the scripts to retrieve different data or perform more complex operations.
  • Analysis Techniques: Add or change the analysis techniques using other R packages or custom functions.
  • Visualisations: Incorporate more advanced visualisations using packages like ggplot2 or plotly.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Happy analysing!

About

This repository contains R scripts to connect to a PostgreSQL database, execute queries, and analyse data using “DBI”, “RPostgres”, and “dplyr”. Perfect for integrating R with PostgreSQL for efficient data analysis.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages