France.R 1.18 KB
Newer Older
Daniel Falster's avatar
Daniel Falster committed
1
2
#!/usr/bin/env Rscript

Georges Kunstler's avatar
Georges Kunstler committed
3
##### FORMAT TRAIT FOR France
4
5
source("R/find.trait/trait.fun.R")
source("R/format.data/format.fun.R")
Georges Kunstler's avatar
Georges Kunstler committed
6
7

### read species names
8
species.clean <- (read.csv("data/raw/France/species.csv", stringsAsFactors = FALSE))
Georges Kunstler's avatar
Georges Kunstler committed
9
10
11
species.clean$Latin_name <- (gsub("_", " ", species.clean$Latin_name))
species.clean$Latin_name_syn<- (gsub("_", " ", species.clean$Latin_name_syn))
species.clean <-  subset(species.clean,subset=!is.na(species.clean$Latin_name_syn))
Georges Kunstler's avatar
Georges Kunstler committed
12
species.clean$sp <- paste("sp",species.clean$code,sep=".")
Georges Kunstler's avatar
Georges Kunstler committed
13
14
species.clean$code <- NULL
## read in data
15
16
data.TRY.std <- readRDS("output/formatted/TRY/data.TRY.std.rds")
max.height <- read.csv(file="output/formatted/France/max.height.csv", stringsAsFactors = FALSE)
Georges Kunstler's avatar
Georges Kunstler committed
17
max.height$Max.height.genus <- FALSE
Georges Kunstler's avatar
Georges Kunstler committed
18
19
### extract and add height
data.traits <- fun.extract.format.sp.traits.TRY(sp=species.clean[["sp"]],sp.syno.table=species.clean,data=data.TRY.std)
Georges Kunstler's avatar
Georges Kunstler committed
20
data.traits <- merge(data.traits,subset(max.height,select=c("sp","Max.height.mean","Max.height.sd","Max.height.genus")),by="sp",all.x=TRUE,all.y=FALSE)
Georges Kunstler's avatar
Georges Kunstler committed
21
### TODO ADD GENUS MEAN FOR HEIGHT IF SPECIES IS MISSING
22
write.csv(data.traits,file="output/formatted/France/traits.csv",row.names = FALSE)
Georges Kunstler's avatar
Georges Kunstler committed
23