###CREATE PP data set #Download data file from https://doi.org/10.5066/P94GV3LC; be sure DWS file is saved as a .csv AND DELETE THE TOP TWO ROWS OF METADATA IN THE .CSV #set working directory to location with the DWS survey data file; #setwd("~/Dropbox/Dissertation/Manuscripts/Regional/RegionalMsProject/Ecosphere/Data Files") PPdat <- read.csv("Wetland_Bird_Study_1995to1997_Dataset.csv") head(PPdat) PPdat <- PPdat[PPdat$pWOODL < 20,] PPdat <- PPdat[PPdat$pSHRUB < 20,] #Wetland area PPdat$surveyArea <- PPdat$SIZE PPdat$r <- sqrt((PPdat$surveyArea*10000)/pi) PPdat$R <- PPdat$r + 400 PPdat$buffArea <- pi*(PPdat$R^2 - PPdat$r^2)/10000 PPdat$area <- (PPdat$buffArea*PPdat$pWETLA/100) + PPdat$surveyArea PPdat$YEAR PPdat2 <- PPdat PPDWMPdata <- data.frame(key = PPdat2$KEY, site = PPdat2$SITEID, year = PPdat2$YEAR, OW = PPdat2$pOW, SM = PPdat2$pSM, EV = PPdat2$pEV, WM = PPdat2$pWM, localSum = PPdat2$COVERSUM, localDiversity = PPdat2$COVERDIVERSITY, Grass400 = PPdat2$pGRASS + PPdat2$pHAYLA, Forest400 = PPdat2$pWOODL, Totwet400 = PPdat2$pWETLA, Crop400 = PPdat2$pCROPL, nLandSum = rep(NA), naturalLandDiversity = rep(NA), class = PPdat2$CLASS, size = PPdat2$surveyArea, area = PPdat2$area, PBGR = PPdat2$PBGR, AMBI = PPdat2$AMBI, VIRA = PPdat2$VIRA, SORA = PPdat2$SORA) #turn into long form spp <- c("PBGR", "AMBI", "VIRA", "SORA") wantedCols <- names(PPDWMPdata)[1:18] PPlong <- data.frame() for(i in spp){ sppCols <- c(wantedCols, i) sppDf <- PPDWMPdata[sppCols] names(sppDf)[19] <- "count" sppDf$species <- rep(i) sppDf <- sppDf[,c(1:18, 20, 19)] PPlong <- rbind(PPlong, sppDf) } #Add in natural land and natural land diversity index for(i in 1:nrow(PPlong)){ PPlong$nLandSum[i] = sum(PPlong$Grass400[i], PPlong$Forest400[i], PPlong$Totwet400[i]) PPlong$naturalLandDiversity[i] <- 1/((((PPlong$Grass400[i]/PPlong$nLandSum[i])*100)^2 + ((PPlong$Forest400[i]/PPlong$nLandSum[i])*100)^2 + ((PPlong$Totwet400[i]/PPlong$nLandSum[i])*100)^2)/10000) } PPlong$data <- rep("PPDWMP") #Read in MMP & CWMP DATASET glDat <- read.csv("GL_Data.csv") #Combine datasets and save data file wetlandData <- rbind(PPlong, glDat) write.csv(wetlandData, "wetlandData.csv", quote=T, row.names=F)