October 2017
Beginner to intermediate
236 pages
7h 38m
English
To connect with the PostgreSQL database server, you need to know the username and password. Here is the R code to connect to the database server, create a database, and insert the data into it:
library(RPostgreSQL) p_word <- { "postgres123" } databaseDriver <- dbDriver("PostgreSQL") con2DB <- dbConnect(databaseDriver, dbname = "postgres", host = "localhost", port = 5432, user = "postgres", password = p_word) dbExistsTable(con2DB, "airlineDB") # Importing CSV file dat1 <- read.csv('USAairlineData2016.csv', header = T, as.is = T) dat1 <- dat1[c("YEAR", "QUARTER", "MONTH", "ORIGIN", "DEST", "DEP_DELAY", "ARR_DELAY")] dat1$ROW_ID <- 1:nrow(dat1) # Writing the data into PostgreSQL data table "airlineDB" dbWriteTable(con2DB, "airlineDB", ...