Commit 516e7d1a authored by fhui28's avatar fhui28
Browse files

minor changes to Fushan and NZ in accordance with milestones

No related merge requests found
Showing with 24 additions and 25 deletions
+24 -25
......@@ -26,7 +26,7 @@ data.fushan$D <- data.fushan[["dbh1"]] ## diameter in cm
data.fushan$dead <- as.numeric(data.fushan$status2 == "dead") ## dummy variable for dead tree 0 alive 1 dead
data.fushan$plot <- rep(NA,nrow(data.fushan)) ## plot code - MISSING
data.fushan$htot <- rep(NA,nrow(data.fushan)) ## height of tree in m - MISSING
data.fushan$tree.id <- data.fushan$tag ## tree unique id
data.fushan$tree.id <- data.fushan$tag ## tree unique id - use tag here as it is unique for each row
data.fushan$sp.name <- rep(NA,nrow(data.fushan))
v <- species.clean$sp
for (i in 1:length(unique(data.fushan$sp))) {
......
......@@ -3,42 +3,48 @@ rm(list = ls())
source("./R/format.function.R")
library(reshape)
######################### READ DATA read individuals tree data
######################### READ DATA read individuals tree and environmental data
data.nz <- read.csv("./data/raw/DataNVS/nz_treedata_growth_130801.csv", header = TRUE,
stringsAsFactors = FALSE, skip = 9)
data.nz <- data.nz[, -1]
data.trait <- read.csv("./data/raw/DataNVS/nz_traits_130801.csv", , header = TRUE,
stringsAsFactors = FALSE)
data.trait <- data.trait[, -1]
data.nz$plid <- gsub("__", "_", data.nz$plid)
data.nz$plid <- gsub("_", ".", data.nz$plid) ## Replace all underscores with a single dot
data.plot <- read.csv("./data/raw/DataNVS/nz_plotinfo_130801.csv", , header = TRUE,
stringsAsFactors = FALSE)
data.plot <- data.plot[, -1]
colnames(data.trait)[1] <- "sp"
data.plot$plid <- gsub("__", "_", data.plot$plid)
data.plot$plid <- gsub("_", ".", data.plot$plid) ## Replace all underscores with a single dot
data.nz$plid <- gsub("__", "_", data.nz$plid)
data.nz$plid <- gsub("_", ".", data.nz$plid) ## Replace all underscores with a single dot
data.nz <- merge(data.nz, data.frame(plid = data.plot$plid, Easting = data.plot$Easting,
Northing = data.plot$Northing, Locality = data.plot$Locality, MAP = data.plot$map, MAT = data.plot$mat, Broadclass = data.plot$BroadClass,
Specificclass = data.plot$SpecificClass, stringsAsFactors = F), sort = T, by = "plid")
rm(data.plot)
###################################### MASSAGE TRAIT DATA Maximum height per species is already available from
###################################### data.trait (in m); so no sd's and only obs per spp
data.trait <- read.csv("./data/raw/DataNVS/nz_traits_130801.csv", , header = TRUE,
stringsAsFactors = FALSE)
data.trait <- data.trait[, -1]
colnames(data.trait)[1] <- "sp"
data.max.height <- data.frame(code = data.trait[["sp"]], Max.height.mean = log10(data.trait[["height.m"]]),
Max.height.sd = NA, Max.height.nobs = 1)
# write.csv(data.max.height,file='./data/process/data.max.height.nz.csv') ## I
# was planning to save processed data in that folder
# write.csv(data.max.height,file='./data/process/data.max.height.nz.csv')
################################################################ FORMAT INDIVIDUAL TREE DATA
## change unit and names of variables to be the same in all data for the tree
data.nz$G <- 10 * (data.nz[["D1"]] - data.nz[["D0"]])/(data.nz[["t1"]] - data.nz[["t0"]]) ## diameter growth in mm per year
data.nz$year <- (data.nz[["t1"]] - data.nz[["t0"]]) ## number of year between measurement
data.nz$D <- data.nz[["D0"]] ## diameter in mm convert to cm
data.nz$D <- data.nz[["D0"]] ## diameter in cm
data.nz$dead <- as.numeric(is.na(data.nz[["D1"]])) ## dummy variable for dead tree 0 alive 1 dead
data.nz$sp <- data.nz$sp
data.nz$plot <- data.nz$plid
data.nz$htot <- rep(NA, length(data.nz[["sp"]])) ## Max height is already available so have as missing
data.nz$tree.id <- data.nz[["tag"]]
data.nz$tree.id <- gsub("__", "_", data.nz$tree.id)
data.nz$tree.id <- gsub("_", ".", data.nz$tree.id) ## tree unique id
data.nz$plot <- data.nz$plid; data.nz$plid <- NULL
data.nz$htot <- rep(NA, nrow(data.nz)) ## Max height is already available so have as missing
data.nz$tree.id <- rep(NA, nrow(data.nz))
#data.nz$tree.id <- gsub("__", "_", data.nz$tree.id)
#data.nz$tree.id <- gsub("_", ".", data.nz$tree.id) ## tree unique id
data.nz$weights <- 1/(pi*(0.5*data.nz$D/100)^2)
########################################## CHANGE COORDINATE SYSTEM DON'T KNOW THE EPSG CODE HERE change coordinates
########################################## system of Easting Northing to be in lat long WGS84
......@@ -60,21 +66,14 @@ data.nz$Lat <- coordinates(data.sp2)[, "Northing"]
rm(data.sp, data.sp2)
###################### ECOREGION merge greco to have no ecoregion with low number of observation
data.nz <- merge(data.nz, data.frame(plot = data.plot$plid, data.plot[, 11:12]),
by = "plot")
table(data.nz$Broad)
###################### PERCENT DEAD
perc.dead <- tapply(data.nz[["dead"]], INDEX = data.nz[["plot"]], FUN = function.perc.dead)
# ## VARIABLE TO SELECT PLOT WITH NOT BIG DISTURBANCE KEEP OFTHER VARIABLES IF
# AVAILABLE (disturbance record)
perc.dead <- tapply(data.nz[["dead"]], INDEX = data.nz[["plot"]], FUN = function.perc.dead2)
data.nz <- merge(data.nz, data.frame(plot = names(perc.dead), perc.dead = perc.dead),
by = "plot", sort = FALSE)
########################################################### PLOT SELECTION FOR THE ANALYSIS
data.nz <- merge(data.nz, data.plot[, c(1, 8:10)], by = "plid")
colnames(data.nz)[colnames(data.nz) %in% c("mat", "map")] <- c("MAT", "MAP")
# colnames(data.nz)[names(data.nz) =='eco_codemerged' ] <- c('ecocode')
vec.abio.var.names <- c("MAT", "MAP")
vec.basic.var <- c("tree.id", "sp", "spname", "plot", "ecocode", "D", "G", "dead",
"year", "htot", "Lon", "Lat", "perc.dead")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment