#How to extra and transform the data from the 'Belgium' dataset
## Libraries ################################################
library(reshape2)
library(dplyr)
library(DImodelsMulti)
#############################################################
## Read in data##################################
data("Belgium")
Belgium_MV <- Belgium[which(Belgium$YEARN == 3), ]
#Top 3 values for each ecosystem function
top <- Belgium_MV %>%
arrange(desc(Y)) %>%
group_by(Var) %>%
slice(1:3)
#Divide by average of top values
top <- aggregate(Y ~ Var, data = top, FUN = "mean")
Belgium_MV$Y <- 100*Belgium_MV$Y
#Sown
condition <- which(Belgium_MV$Var == "Sown")
Belgium_MV$Y[condition] <- Belgium_MV$Y[condition] /
top[1, "Y"]
#N
condition <- which(Belgium_MV$Var == "N")
Belgium_MV$Y[condition] <- Belgium_MV$Y[condition] /
top[2, "Y"]
#Weed
condition <- which(Belgium_MV$Var == "Weed")
Belgium_MV$Y[condition] <- Belgium_MV$Y[condition] /
top[3, "Y"]
Belgium_MV
Run the code above in your browser using DataLab