- Step: Install dependencies (PostgreSQL, JDBC-Connector for PostgreSQL and R)
sudo apt-get install postgresql libpostgresql-jdbc-java r-base-core r-cran-rjava r-cran-dbi
- Step: Open Terminal & run R with
R
- Step: Install JDBC-Package (RJDBC) for R
install.packages(c("RJDBC"))
- Step: Connect to your database from within R
# Include JDBC package
library(RJDBC)
# Initialize JDBC PostgresSQL driver
drv <- JDBC("org.postgresql.Driver", "/usr/share/java/postgresql-jdbc4-9.1.jar", identifier.quote="`")
# Establish connection to database
conn <- dbConnect(drv, "jdbc:postgresql://localhost/database", "user", "pw")# Run your SQL select query
data <- dbGetQuery(conn, "select * from iris where Species='setosa'") - That's it :)
Freitag, 6. September 2013
Process PostgreSQL data in R with Ubuntu Linux 12.04
Here is the ultimate overview for all who like to work with R in Ubuntu and who want to process data from PostgreSQL. As a requirement, I assume that you already setup your PostgreSQL database.
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen