In [48]:
# install.packages("RPostgreSQL")
require("RPostgreSQL")
require("ggplot2")
In [4]:
# load the PostgreSQL driver
drv <- dbDriver("PostgreSQL")
In [19]:
# create a connection to the postgres database
# set the search path to the mimiciii schema
con <- dbConnect(drv, dbname = "mimic",
host = "localhost", port = 5432,
user = "mimic")
dbSendQuery(con, 'set search_path to mimiciii')
In [34]:
# show a list of tables
dbListTables(con)
Out[34]:
In [90]:
# assign ICU length of stay to variable
iculos = dbGetQuery(con, "select los from icustays where los >= 0 and los <=20")
In [93]:
# plot histogram of length of stay in the ICU
qplot(iculos$los, geom="histogram", binwidth = 1, main = "Length of stay in the ICU",
xlab = "Length of stay, days", fill=I("#9ebcda"), col=I("#FFFFFF"))
In [ ]:
# close the connection
dbDisconnect(con)
dbUnloadDriver(drv)