EdR.extract <- function(dataf, timecols, valcols) {
#Example: datanew <- EdR.extract(data1, c("doy_dbl", "TTc"), c("Leaf", "Stem", "Root", "Grain"))
#Start to form the result
temp1 <- dataf[timecols] # Extract the time columns from the input data frame
result <- temp1 # Make a copy of the time column data frame
curr_valcol <- as.character(valcols[1]) # Get the name of the first value column
result$value <- dataf[,curr_valcol] # Get the values from the column
result$value_type <- curr_valcol # Store the name of the value column
#Add the rest of the value columns
if(length(valcols)>1) {
for(i in 2:length(valcols)) {
temp2 <- temp1 # Make a copy of the time column data frame
curr_valcol <- as.character(valcols[i]) # Get the name of the current value column
temp2$value <- dataf[,curr_valcol] # Get the values from the column
temp2$value_type <- curr_valcol # Store the name of the value column
result <- rbind(result, temp2) # Add this to the result
}
}
#Return the result
return(result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.