Getting BBS Data into R

I like to start with a clean slate. Set your working directory to wherever you store your BBS, etc. files that will go into the script.

rm(list = ls())

Here, you need to put the full path to the BBS files.

BBS <- rbindlist(lapply(list.files("",full.names=TRUE),read.csv))

This following line creates a unique identifier for each BBS route that can be used to match up information in the other files. I chose the name “rteno” because it’s the same variable name used in spatial data distributed for BBS. This is a 1-2 digit state identifier, and a 3-digit number representing the route.

BBS$rteno <- paste(BBS$statenum,formatC(BBS$Route, width=3, flag="0"),sep="")

Now onto those supplementary files you downloaded with the BBS data…

routeinfo <- read.csv("weather.csv")

Create the same route identified (rteno) to merge with the BBS data, and then keep only the columns you need.

routeinfo <- routeinfo[c("Year","ObsN","rteno","RunType")]

Often for BBS analyses, you have to consider whether or not it was an observer’s first year.

routeinfo$firstyear <- c(1L,routeinfo$ObsN[-1]!=routeinfo$ObsN[-nrow(routeinfo)])
BBS <- merge(BBS,routeinfo,by=c("rteno","Year"))


route_data <- read.csv("routes.csv")
route_data <- route_data[c("rteno",...)]
BBS <- merge(BBS,route_data,by="rteno")

Now, a few things you might want to do to clean up the data: get rid of sub-par runs, and keep only the standard protocol.

BBS <- BBS[BBS$RunType > 0,]
BBS <- BBS[BBS$RPID < 102,]

Here’s the R script for download: BBS.txt

Leave a Reply

Your email address will not be published. Required fields are marked *