-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_plot_info_file.R
63 lines (45 loc) · 1.85 KB
/
create_plot_info_file.R
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
62
create_plot_info_file <- function() {
library(tidyverse)
# create version file -----------------------------------------------------
# source("./code/create_version_file.R")
# dataset<-"plots"
# create_version_file(dataset)
# load the complete and clean Heliconia dataset ---------------------------
# these are the years each fragment was isolated
isolation <- tibble(
"bdffp_no" = c(2107, 2108, 1104, 3114, 2206, 1202, 3209),
"yr_isolated" = c(1984, 1984, 1980, 1983, 1984, 1980, 1983)
) %>%
mutate(across(where(is.double), as.factor))
# select the plot id variables
ha_plots <- read_csv("./data/survey_clean/heliconia_survey_clean.csv",
show_col_types = FALSE) %>%
select(
"plot_id",
"habitat",
"ranch",
"bdffp_reserve_no"
) %>%
distinct() %>%
arrange(plot_id) %>%
mutate(ranch = recode_factor(ranch, "PortoAlegre" = "porto alegre")) %>%
mutate(ranch = recode_factor(ranch, "DIM" = "dimona")) %>%
mutate(ranch = recode_factor(ranch, "PAL" = "porto alegre")) %>%
mutate(ranch = recode_factor(ranch, "EST" = "esteio")) %>%
mutate(habitat = recode_factor(habitat, "1-ha" = "one")) %>%
mutate(habitat = recode_factor(habitat, "10-ha" = "ten")) %>%
mutate(habitat = recode_factor(habitat, "CF" = "forest")) %>%
mutate(bdffp_reserve_no = replace(bdffp_reserve_no, bdffp_reserve_no == "none", NA)) %>%
rename(
"bdffp_no" = "bdffp_reserve_no"
) %>%
left_join(isolation, by="bdffp_no")
# save the csv file -------------------------------------------------------
if (!dir.exists("./data/survey_clean")){
dir.create("./data/survey_clean")
}else{
# print(" ")
}
print("The file has been saved to: 'data/survey_clean/HDP_plots.csv' ")
write_csv(ha_plots, "./data/survey_clean/HDP_plots.csv")
}