knitr::opts_chunk$set(echo = TRUE)

Reshape to wide for demographic info, calculate summaries, etc

Libraries

library(here)
library(reshape2)
library(car)
library(stringi)

Load cleaned and scrubbed data

Data has been cleaned to removed typos and basic prep done for statistics

filename <- "mencia_cleaned.csv"
filename <- here("data-raw",
                  "data-raw-mencia",
                  "mencia_all_captures_by_year",
                  filename)

mencia <- read.csv(filename)

Order sites by age

mencia$site <- factor(mencia$site,
                      levels = c("La Cueva",
                                 "La Caoba",
                                 "Morelia",
                                 "El Corral"))

Cast for demographic summaries

Identify first instance of bird occuring. (I checked - all birds have the same age code even if recaptured; recaps rare regardless)

# i.unique <- match(unique(mencia$band),mencia$band)
# 
# length(which(duplicated(mencia$band) == TRUE))

cast by age

# age.cast <- dcast(data= mencia[i.unique,],
#       formula = species + status ~ site,
#       value.var = "site",
#       fun.aggregate = length)
# 
# 
# age.cast[which(age.cast$status == "mig"), ]

cast by sex

# sex.cast <- dcast(data= mencia[i.unique,],
#       formula = species + status  ~ site + sex,
#       value.var = "site",
#       fun.aggregate = length)
# 
# 
# sex.cast[which(sex.cast$status == "mig"), ]

Save output

save .csv files

save to raw data folder

# focal spp and summary output
# filename <- "focals_herbdat_16.csv"
# filename <-here("data-raw","data-raw-herb","herb_veg_16",
#       filename)
# write.csv(focals.herbdat.16, 
#           file = filename,row.names = F)
# 
# 
# #cover by species
# filename <- "cover_by_spp_herbdat_16.csv"
# filename <-here("data-raw","data-raw-herb","herb_veg_16",
#       filename)
# write.csv(cover.by.spp.herbdat.16, 
#           file = filename,row.names = F)
# 
# 
# 
# #pres abs by spp
# filename <- "presabs_by_spp_herbdat_16.csv"
# filename <-here("data-raw","data-raw-herb","herb_veg_16",
#       filename)
# write.csv(presabs.by.spp.herbdat.16, 
#           file = filename,row.names = F)

save .RData files

saved to "data" folder where working data for real analyses is stored

# filename <- "focals_herbdat_16.RData"
# filename <-here("data",
#       filename)
# save(focals.herbdat.16, 
#           file = filename,row.names = F)



brouwern/DRmencia documentation built on May 6, 2019, 12:24 p.m.