[R] modifying tbrm function

DAVID ARTETA GARCIA darteta001 at ikasle.ehu.es
Fri Jun 6 10:24:46 CEST 2008


Hi,

I haven´t much experience on writing functions and would like to  
modify the simple tbrm() function from package dplR in order to save  
the weights that it produces. I have tried using the superassignment  
operator as explained in the R intro, but is this the right way to  
save a variable within a function?  This is my code

mytukey <- function (x, C = 9)
{
     wt = rep(0, length(x))
     x.med = median(x)
     S.star = median(abs(x - x.med))
     w0 = (x - x.med)/(C * S.star + 1e-06)
     lt0.flag = abs(w0) <= 1
     wt[lt0.flag] = ((1 - w0^2)^2)[lt0.flag]
     t.bi.m = sum(wt * x)/sum(wt)
     myweights<<-wt  # this is my added line
     t.bi.m

}


Thanks,

D.



More information about the R-help mailing list