-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data_plot_summary.R
79 lines (57 loc) · 2.23 KB
/
Data_plot_summary.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
###################################################################
# 23 Septiembre 2020 Laura Giraldo
#
# Script para reorganizar los valores de los rasgos por parcela
# y especie usando un formato largo de los datos, e incluyendo
# los valores de suelo
#
###################################################################
# Cargar librerias
library(here)
library(tidyr)
library(dplyr)
library(readxl)
library(xlsx)
# Cargar archivo
datos <- read_excel(here("Datos","Finales", "Sp_trait_values.xlsx"))
colnames(rasgos)
#saco primero un resumen de las abundancias
abund <- datos %>% group_by(species, Plot) %>%
select("species", "Plot",
"sp_plot_abundance", "total_plot_abundance", "prop_sp_ab_plot",
"abs_abund_sp", "rel_abund") %>%
summarize_if(is.numeric, mean)
View(abund)
abund$tmp_key <- paste(abund$Plot,"_",abund$species)
View(abund)
# Excluir columnas que no son necesarias
colnames(datos)
datos <- datos[ , !(names(datos) %in% c("Id", "prop_sp_ab_plot", "Elevation_corrected",
"abs_abund_sp", "rel_abund",
"DBH","Height","LFM","LDW",
"SoilDepth","Id_Tree","Locality",
"Collector_number","mean_plot_elev",
"Genus","Clade" ,"ID_GPS_tmp", "Latitude_corrected",
"Longitude_corrected","SoilDepth",
"Soil_NO3NH4ratio"))]
colnames(datos)
dim(datos)
# Formato largo
datos_tmp <- datos%>% # Summary by group using dplyr
group_by(species, Plot) %>%
summarize(LDMC = mean(LDMC),
LA=mean(LA),
SLA=mean(SLA),
LNmass=mean(LNmass),
LPmass=mean(LPmass),
LeafNP=mean(LeafNP) )
View(datos_tmp)
datos2 <- gather_(datos_tmp,
key_col = "Trait",
value_col = "Trait_value",
gather_cols = c("LDMC","LA","SLA","LNmass",
"LPmass","LeafNP")
)
dim(datos2)
View(datos2)
#write.xlsx(datos2, here("Datos","Mean_trait_values.xlsx"))