#' Retrieve bin with highest value
#'
#' @param files Vector. A vector of .csv file names (e.g. LBG simulation files)
#' @param path Vector. A vector with path to files folder.
#' @param bin Vector. A vector of the column names for bin to use in the analyses (e.g. midpoint or bin number)
#' @param value Vector. A vector of the column names for value to use in the analyses (e.g. richness or mean)
#' @return Vector. A vector of the bin with highest value.
#' @export
getMax <- function(files, path = NULL, bin, value){
wd <- getwd()
setwd(path)
if(length(files >= 2)){
data <- lapply(files, function(x){
tmp <- read.csv(x)
bintmp <- tmp[paste(bin)]
valuetmp <- tmp[paste(value)]
tmp <- cbind.data.frame(bintmp, valuetmp)
colnames(tmp) <- c("bin", "value")
tmp <- tmp[which.max(tmp$value),]
})
names <- tools::file_path_sans_ext(files)
names(data) <- names
data <- do.call(rbind.data.frame, data)
}
else{
data <- read.csv(files)
data <- cbind.data.frame(bin, value)
data <- data[which.max(data$value),]
}
setwd(wd)
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.