Commit 86b60005 authored by Georges Kunstler's avatar Georges Kunstler
Browse files

dplyr for NFI plus new US data

parent 299a2610
This diff is collapsed.
......@@ -2,6 +2,7 @@
### MERGE us DATA Edited by FH
library(reshape, quietly = TRUE)
library(dplyr)
source("R/format.data/format-fun.R")
dir.create("output/formatted/US", recursive = TRUE, showWarnings = FALSE)
......@@ -10,18 +11,14 @@ dir.create("output/formatted/US", recursive = TRUE, showWarnings = FALSE)
species.clean <- read.csv("data/raw/US/REF_SPECIES.CSV",
stringsAsFactors = FALSE)
## select column to keep
species.clean <- subset(species.clean,
select = c("SPCD", "GENUS", "SPECIES", "VARIETY",
"SUBSPECIES", "SPECIES_SYMBOL"))
species.clean$Latin_name <- paste(species.clean[["GENUS"]],
species.clean[["SPECIES"]],
sep = " ")
species.clean$Latin_name_syn <- paste(species.clean[["GENUS"]],
species.clean[["SPECIES"]],
sep = " ")
species.clean <- select(species.clean,
SPCD, GENUS, SPECIES, VARIETY,
SUBSPECIES, SPECIES_SYMBOL)
names(species.clean)[1] <- "sp"
species.clean[["sp"]] <- paste("sp", species.clean[["sp"]], sep = ".")
species.clean <- mutate(species.clean,
Latin_name = paste(GENUS, SPECIES, sep = " "),
Latin_name_syn= paste(GENUS, SPECIES, sep = " "),
sp = paste('sp', sp, sep ='.'))
## LOAD QUANTILE OF HEIGHT AND FORMAT AS OTHER
data.max.height <- read.csv("data/raw/US/FiaSpMaxHt.csv",
......@@ -33,11 +30,22 @@ data.max.height <- data.frame(sp = data.max.height$SpCd,
write.csv(data.max.height, file = "output/formatted/US/max.height.csv")
#### READ DATA US
data.us <- read.csv("data/raw/US/FIA51_trees_w_supp.csv",
header = TRUE, stringsAsFactors = FALSE)
data.us <- read.csv("data/raw/US/FIA51_trees.csv",
header = TRUE, stringsAsFactors = FALSE)
#MCV remove trees <10 cm dbh
data.us <- subset(data.us, subset = (data.us$InitDbh>=10) )
library(dplyr)
data.us <- filter(data.us, InitDbh>=10 & !is.na(InitDbh) )
data.us.plot <- read.csv("data/raw/US/PlotIDInfo3.csv",
header = TRUE, stringsAsFactors = FALSE)
data.us.plot <- mutate(data.us.plot, PLOT_ID = paste0(Plot, CountyCd, StateCd))
data.us <- left_join(data.us, data.us.plot, by = 'PlotID')
data.us <- mutate(data.us, PLOT_ID_C = PlotID)
data.us$PlotID <- NULL
## NEED TO GET THE CENSUS
## MASSAGE TRAIT DATA HEIGHT DATA FOR TREE MISSING BRING US DATA FOR HEIGHT OVER
......@@ -61,10 +69,10 @@ data.us$dead <- as.numeric(data.us$FinalDbh < 0)
data.us$sp <- as.character(data.us[["Species"]]) ## species code
data.us[["sp"]] <- paste("sp", data.us[["sp"]], sep = ".")
data.us$cluster <- rep(NA, nrow(data.us)) # ## cluster code
data.us$plot <- as.character(data.us[["PlotID"]]) ## plot code
data.us$plot <- as.character(data.us[["PLOT_ID"]]) ## plot code
data.us$htot <- rep(NA, length(data.us[["Species"]]))
## height of tree in m - MISSING
data.us$tree.id <- as.character(data.us$TreeID)
data.us$tree.id <- as.character(paste(data.us$TreeID, data.us$SubplotNumber, sep = '.'))
data.us$obs.id <- 1:nrow(data.us) ## tree unique id
data.us$sp.name <- species.clean[match(data.us$sp, species.clean$sp),
"Latin_name"]
......@@ -105,7 +113,7 @@ data.us$BA.G[data.us$sp.name %in% sp.palm.fern] <- NA
## census but tree id is used for the individual random effect
data.us$census <- rep(1, nrow(data.us))
data.us$census <- data.us$StartMeasYear
### add plot weights for computation of competition index (in 1/m^2)
data.us$weights <- 1/(10000 * data.us[["PlotSize"]])
......
Markdown is supported
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