Rii – R Script

Bit of low hanging fruit. A function to calculate Rii from datasets in R.

rii <- function(x, j, var)
{
s1 <- subset(x, Microsite == “Shrub”, select=var)
o1 <- subset(x, Microsite == “Open”, select=var)
return1 <- (s1 – o1)/ (s1+o1)
x1 <- x[seq(1, nrow(x), by = 2),]
return2 <- cbind(x1[j], return1)
return2[is.na(return2)] <- 0
print(return2)
}

where:

x = data frame (matrix)

var= response variables

j = explanatory variables