Let’s access an SQL database directly from R using dplyr
.
Either use an existing copy of the portal_mammals.sqlite
database or download
a new copy. You
should be able to link to the surveys
table in the database using:
library(DBI)
portaldb <- dbConnect(RSQLite::SQLite(), "portal_mammals.sqlite")
surveys <- tbl(portaldb, "surveys")
surveys
is actually a connection to the database, which means that the table
remains external to the R environment. Also, we won’t need to worry about it
printing out huge numbers of rows when we look at it.
year
, month
, day
, and species_id
columns in that order.year
, species_id
, and weight in
kilograms of each individual, with no null weights.distinct()
function to print the species_id
for each
species in the dataset that has been weighed.