An error occurred while loading the file. Please try again.
-
markvanderwel authored429fd78a
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR Canada
source("R/find.trait/trait.fun.R")
### read species names
data.tree <- read.csv("output/formatted/Canada/tree.csv", stringsAsFactors = FALSE)
species.clean <- data.frame(sp=data.tree[!duplicated(data.tree[["sp"]]),"sp"],
Latin_name=data.tree[!duplicated(data.tree[["sp"]]),"sp.name"],
Latin_name_syn=data.tree[!duplicated(data.tree[["sp"]]),"sp.name"],
stringsAsFactors =FALSE)
## delete the sp code with no species
species.clean <- subset(species.clean,subset=!is.na(species.clean$Latin_name))
## read in data
data.TRY.std <- readRDS("output/formatted/TRY/data.TRY.std.rds")
## read us max height
max.height <- read.csv(file="output/formatted/US/max.height.csv", stringsAsFactors = FALSE)
#manually assign max height to Alnus spp. (alder), from: http://plants.usda.gov/java/charProfile?symbol=ALINR
max.height[dim(max.height)[1]+1,] <- c(dim(max.height)[1]+1,350,4.9,NA,NA)
max.height$sp <- paste("sp",max.height$sp,sep=".")
data.traits <- fun.extract.format.sp.traits.TRY(sp=species.clean[["sp"]],sp.syno.table=species.clean,data=data.TRY.std)
data.traits <- merge(data.traits,subset(max.height,select=c("sp","Max.height.mean","Max.height.sd")),by="sp",all.x=TRUE,all.y=FALSE)
### TODO ADD GENUS MEAN FOR HEIGHT IF SPECIES IS MISSING
write.csv(data.traits,file="output/formatted/Canada/traits.csv",row.names = FALSE)