[R] scoping issues?
tom wright
tom at maladmin.com
Thu Dec 8 14:52:42 CET 2005
Thanks for the answers, yup the missing c() was what was throwing me.
And thanks Barry for the slighly more elegant code, I'm a bit post
christmas party here and not thinking as straight as I should be.
On Thu, 2005-08-12 at 06:47 -0500, tom wright wrote:
> Can anyone please help me understand whats happening here?
> Thanks
> Tom
>
> getAmpRatio<-function(v_amps){
> #calculates the amplitude ratios between the 3 largest amps and the
> rest
> bigamp<-0
> map<-rep(TRUE,length(v_amps))
>
> for(iLoc in 1:3){
> bigamp<-bigamp+max(v_amps)
> map[which.max(v_amps)]<-FALSE
> v_amps<-v_amps[map]
> map<-rep(TRUE,length(v_amps))
> }
> browser()
> return(bigamp/mean(v_amps))
> }
>
> amps<-c(1,2,3,3,3,2,1)
> getAmpRatio(amps)
>
> Browse[1]> v_amps
> [1] 1 1 2 2 1
> Browse[1]> c(amps[1],amps[2],amps[3],amps[7],amps[8])
> [1] 1 1 2 2 1
> Browse[1]> mean(v_amps)
> [1] 1.4
> Browse[1]> mean(amps[1],amps[2],amps[3],amps[7],amps[8])
> [1] 1
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list