#' Convert area to compositional
#'
#' Convert area to compositional
#' @param dataLU data.frame of LU measurements, in area unit.
#' @param compCol Land use column whether its name or its index.
#' @keywords landuse composition
#' @export
#' @examples
area2comp <-function(dataLU, compCol, IDcol){
data.lu = dataLU
data.lu$ID = dataLU[,which(names(dataLU) == IDcol)]
data.lu$Shape_Area = as.numeric(data.lu$Shape_Area)
list_station = unique(data.lu$ID)
list_lu = unique(data.lu[,which(names(data.lu) == compCol)])
LU.f = matrix(0, nrow = length(list_station), ncol = length(list_lu), dimnames=list(list_station, list_lu))
for(i in 1:length(list_station)){
name = list_station[i]
LU.temp = data.lu[which(data.lu$ID==name),]
list.sec = unique(LU.temp[,which(names(LU.temp) == compCol)])
for(j in list.sec){
LU.f[i,which(list_lu == j)] = as.numeric(sum(LU.temp$Shape_Area[which(LU.temp[,which(names(LU.temp) == compCol)]==j)]+6)/sum(LU.temp$Shape_Area+6))
}
}
LU.f = as.data.frame(LU.f)
LU.f$ID = list_station
return(LU.f)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.