##* GET POPULATION THERMAL PERFORMANCE TRAITS
#' Get population thermal performance traits
#'
#' Gets an entire populations thermal performance traits from TP data.
#'
#' @param TPD A population's temperature performance dataset with ID, Tm & P columns
#'
#' @param Degree Degree of the polynomial regression that will be used to extract the data.
#'
#' @param Pmin The minimal thermal performance. From it CTmax & CTmin will be determined
#'
#' @return A datset of three columns: "ID" for individual, "trait" with trait ids and "value" for each trait.
#'
#' @examples
#'
#'@export
get_pop_tpts <- function(TPD, Degree, Pmin){
# grouping original data and nesting it
D <- TPD %>% group_by(ID) %>% nest()
# extract first individiual tpts
ind_tpdata <- as.data.frame(D$data[1]) # extract individual tpd
ind_tpts <- get_tpts( Tm = ind_tpdata$Tm, P = ind_tpdata$P, Degree = Degree, Pmin = Pmin) # get individuals tpts
ind_id <- rep(as.character(D$ID[1]), nrow(ind_tpts)) # get individual ID repeated for as many tpts as you have
ind <- cbind(ind_id, ind_tpts) # join together
ind <- rename(ind, ID = ind_id) # renaming ID variable
pop_tpts <- ind # establish base to rbind next individuals
# extract population's tpts
for (i in 2:nrow(D)){
ind_tpdata <- as.data.frame(D$data[i]) # extract individual tpd
ind_tpts <- get_tpts( Tm = ind_tpdata$Tm, P = ind_tpdata$P, Degree = Degree, Pmin = Pmin) # get individuals tpts
ind_id <- rep(as.character(D$ID[i]), nrow(ind_tpts)) # get individual ID repeated for as many tpts as you have
ind <- cbind(ind_id, ind_tpts) # join together
ind <- rename(ind, ID = ind_id) # renaming ID variable
pop_tpts <- rbind(pop_tpts,ind) # rbind each individuals data to pop data
}
return(pop_tpts)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.