Skip to content
Prev 199304 / 398503 Next

performing operations on a dataframe

On 11/06/2009 05:30 AM, Lanna Jin wrote:
Hi Lanna,
Perhaps if you define your different functions like this:

transfun2000<-function(x) x/146
transfun2001<-function(x) x/237

and then write a function like this:

mytrans<-function(x) {
  yearlabels<-unique(x$Year)
  nyears<-length(yearlabels)
  transcooc<-rep(NA,nyears)
  for(i in 1:nyears) {
   cooc<-somefunction(x[x$Year == yearlabels[i],])
   transcooc[i]<-do.call(paste("transfun",yearlabels[i],sep=""),...)
  }
  return(transcooc)
}

although this is largely guesswork.

Jim