My program takes a data.frame and crunches the numbers. At one point, values from j-th column are multiplied by a predefined values that depends on the column name (species name, actually - it's en ecological index). So far, I've been providing these values via a second data.frame by matching column names. What would be an efficient way of integrating fixed variable values within a function? I would like my program to be as portable as possible, without the need for a second data.frame file.
EDIT
This is the function. I'm trying to improve the second line (index <- read.table...) so that it would not depend on the outside source.
macroIndex <- function(obj, index) {
index <- read.table("conv.csv", header=T, dec=",")
a <- c()
b <- names(obj)
for (i in 2:length(obj)) {
obj[i] <- obj[i] * index[which(index==b[i]), 2]
}
obj
}
Another solution I tried, while it may not seem pretty, it gets the job done. I use dput(index) and create a permanent object which I then insert into my function.