Let’s access an SQL database directly from R. Install the RSQLite
package (and
the dbplyr
package if you haven’t already).
Either use an existing copy of the portal_mammals.sqlite
database or download
a new copy. You
should now be able to link to the surveys table in the database using:
portaldb <- src_sqlite("portal_mammals.sqlite")
surveys <- tbl(portaldb, "surveys") %>% tbl_df
surveys
will be a tbl_df
, which means that we won’t need to worry about it
printing out huge numbers of rows in the answers below.
Using this table in the database:
nrow()
function to determine how many records are represented in this
dataset.distinct()
function to print the species_id for each
species in the dataset that have been weighed.NL
) in this dataset.dplyr
I’d
recommend checking out the
dplyr
vignette.
Vignette’s can be a great way to learn how to use packages in R. If you’re in
a hurry you can also do a search for count
in the page.