-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleaning_bien.lifeform.R
More file actions
executable file
·65 lines (38 loc) · 2.14 KB
/
Copy pathcleaning_bien.lifeform.R
File metadata and controls
executable file
·65 lines (38 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## cleaning BIEN life form levels
## initally 139 levels which is not great
## I want to clean themn to less than 10 classifications and then the combinations thereof
##to do
## name the life form dataset "mydata"
mydata <- lifeform_bien
levels(factor(mydata$trait_value))
mydata$trait_value %>% factor(.) %>% table(.) %>% .[order(.)]
## making naming consistant
mydata$trait_value <- tolower(mydata$trait_value)
tree <- c("tree", "tree*", "tree ", "tree\\_", "medium sized tree", "medium size tree", "phanerophyte*", "small_phanerophyte")
mydata$trait_value <- gsub(paste(tree, collapse="|"),"phanerophyte", mydata$trait_value)
shrub <- c("shrub", "shru", "shrub*")
mydata$trait_value <- gsub(paste(shrub, collapse="|"), "shrub",mydata$trait_value)
epiphyte <- c("epiphyte")
mydata$trait_value <- gsub(paste(epiphyte, collapse="|"),"epiphyte", mydata$trait_value, ignore.case = TRUE)
geophyte <- c("geophyte\\*")
mydata$trait_value <- gsub(paste(geophyte, collapse="|"), "geophyte",mydata$trait_value, ignore.case = TRUE)
hemicryptophyte <- c("hemicryptophyte", "hemicr")
mydata$trait_value <- gsub(paste(hemicryptophyte, collapse="|"), "hemicryptophyte",mydata$trait_value, ignore.case = TRUE)
herb <- c("herb")
mydata$trait_value <- gsub(paste(herb, collapse="|"), "herb", mydata$trait_value, ignore.case = TRUE)
forb <- c("forb")
mydata$trait_value <- gsub(paste(forb, collapse="|"), "forb", mydata$trait_value, ignore.case = TRUE)
liana <- c("liana", "vine")
mydata$trait_value <- gsub(paste(liana, collapse="|"), "liana", mydata$trait_value, ignore.case = TRUE)
parasite <- c("parasite")
mydata$trait_valuez <- gsub(paste(parasite, collapse="|"), "parasite",mydata$trait_value, ignore.case = TRUE)
## remove unwanted characters
descriptions <-c("\\*")
mydata$trait_value <-gsub(paste(descriptions, collapse = "|"), "", ignore.case = TRUE, mydata$trait_value)
mydata <- mydata[mydata$trait_value %in% c("therophyte", "geophyte", "phanerophyte","hemicryptophyte"),] # hydrophyte?
## look again at levels
#levels(factor(mydata$OrigValueStr))
#mydata$OrigValueStr %>% factor(.) %>% table(.) %>% .[order(.)]
bien_lfs <-droplevels(mydata)
rm(mydata)
## finished