https://github.com/tom-n-walker/uphill-plants-soil-carbon
Tip revision: a9e7a872d22a45dbd91bb00751d522812138eefd authored by Tom Walker on 08 February 2022, 15:18:56 UTC
Additional and revised analysis in response to author comments.
Additional and revised analysis in response to author comments.
Tip revision: a9e7a87
load_soil.R
################################################################################
#### Project: Lowland plant migrations alpine soil C loss
#### Title: Function | Load soil data
#### Author: Tom Walker (thomas.walker@usys.ethz.ch)
#### Date: 26 May 2021
#### ---------------------------------------------------------------------------
load_soil <- function(){
# load pools
pools <- fread("./data/field_soil_data.csv") %>%
# edit treatment and column names, remove species data
mutate(Treatment = substr(Treatment, nchar(Treatment), nchar(Treatment))) %>%
mutate(Site = tolower(Site)) %>%
# add leading zero to block
mutate(Block = ifelse(
nchar(Block) == 3,
Block,
paste0(substr(Block, 1, 1), "0", substr(Block, 2, 2))
)) %>%
# sort column names and select variables
dplyr::rename_with(.cols = Sample:Treatment, tolower) %>%
select(-sample) %>%
as.data.frame
# load lavey extra data and combine
lav <- fread("./data/field_deep_soil_data.csv") %>%
as.data.frame %>%
select(Block:Elevation, MR.ugC.g.h:CUE) %>%
rename_with(.cols = Block:Elevation, tolower) %>%
mutate(site = "lavey") %>%
# add leading zero to block
mutate(block = ifelse(
nchar(block) == 3,
block,
paste0(substr(block, 1, 1), "0", substr(block, 2, 2))
)) %>%
mutate(treatment = substr(treatment, nchar(treatment), nchar(treatment)))
# combine
out <- pools %>%
left_join(., lav, by = c("site", "block", "treatment", "elevation")) %>%
# setup proper units
rename(Rm = MR.ugC.g.h,
Gm = MG.ugC.g.h,
RmM = MRm.ugCmic.g.h,
GmM = MGm.ugCmic.g.h) %>%
mutate(Cmic = Cmic/1000,
CUE = CUE*100,
RmM = RmM * 1000,
GmM = GmM * 1000)
# return
return(out)
}