[R] scoping issues?
    Barry Rowlingson 
    B.Rowlingson at lancaster.ac.uk
       
    Thu Dec  8 19:38:42 CET 2005
    
    
  
tom wright wrote:
 > Browse[1]> mean(amps[1],amps[2],amps[3],amps[7],amps[8])
 > [1] 1
  For starters, this just returns mean(amps[1]). 'mean' computes the 
mean of the first argument, the others are slurped up by '...' and in 
this case thrown into the bin. You want to do 
mean(c(amps[1],amps[2],amps[3] and so on. Wrap them into a single vector.
  For main course, I think you can do it like this:
getAR <- function(v.amps){
   sv=sort(v.amps)
   sum(sv[1:3])/mean(sv[-(1:3)])
}
  - which computes the ratio of the sum of the three biggest over the 
mean of the remainder. Which I think is what your code looks like its 
trying to do!
  An example input/output would be nice. My code gives:
  > amps<-c(1,2,3,3,3,2,1)
  > getAR(amps)
  [1] 1.454545
  but I still dont know if that's what it should be!
  For dessert, I don't think its a scoping issue, I think you've not 
really explained what the problem is...
Baz
    
    
More information about the R-help
mailing list