mbuffer {biology} | R Documentation |
~~ A concise (1-5 lines) description of what the function does. ~~
mbuffer(asc, sites, dist, fun)
asc |
~~Describe asc here~~ |
sites |
~~Describe sites here~~ |
dist |
~~Describe dist here~~ |
fun |
~~Describe fun here~~ |
~~ If necessary, more details than the description above ~~
~Describe the value returned If it is a LIST, use
comp1 |
Description of 'comp1' |
comp2 |
Description of 'comp2' |
...
....
~~further notes~~
~Make other sections like Warning with section{Warning }{....} ~
~~who you are~~
~put references to the literature/web site here ~
~~objects to See Also as help
, ~~~
##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (asc, sites, dist, fun) { require(adehabitat) require(sp) nm <- deparse(substitute(asc)) bpu <- .buffer.point.unic(asc, dist) attr(bpu, "cellsize") <- attr(asc, "cellsize") ss <- coordinates(sites) cs <- attr(bpu, "cellsize") b <- list() cc <- data.frame(sites = NULL) cc.data <- NULL cc.sites <- NULL asc.x <- c(attr(asc, "xll"), attr(asc, "xll") + (attr(asc, "cellsize") * (attr(asc, "dim")[1]))) asc.y <- c(attr(asc, "yll"), attr(asc, "yll") + (attr(asc, "cellsize") * (attr(asc, "dim")[2]))) j <- 0 for (i in 1:length(ss[, 1])) { xl <- c(ss[i, 1] - ((ncol(bpu) - 1) * cs)/2, ss[i, 1] + ((ncol(bpu) - 1) * cs)/2) yl <- c(ss[i, 2] - ((nrow(bpu) - 1) * cs)/2, ss[i, 2] + ((nrow(bpu) - 1) * cs)/2) if (in.boundary(xl + c(-dist, dist), yl + c(-dist, dist), asc.x, asc.y)) { bb <- try(subsetmap(asc, xlim = xl, ylim = yl), TRUE) j <- j + 1 b[[j]] <- bb * bpu if (fun == "mean") cc.d <- mean(b[[j]], na.rm = T) if (fun == "sum") cc.d <- sum(b[[j]], na.rm = T) if (fun == "percent") cc.d <- sum(b[[j]], na.rm = T)/sum(bpu, na.rm = T) cc.data <- rbind(cc.data, DATA = cc.d) cc.sites <- rbind(cc.sites, SITES = as.character(sites[i, ]$SITE)) } else { DEM <- NA cc.data <- rbind(cc.data, DEM) cc.sites <- rbind(cc.sites, SITES = as.character(sites[i, ]$SITE)) } } cc <- data.frame(SITES = cc.sites, DATA = cc.data) dimnames(cc)[[2]] <- c("SITES", nm) return(cc) }