[R] (no subject)

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Thu Nov 11 22:23:33 CET 2004


Sorry! I had omitted to copy in an essential line in the code
below:

On 11-Nov-04 Ted Harding wrote:
> On 11-Nov-04 Wei Yang wrote:
>> Hi, 
>> 
>> I have a list of numbers. For each of the numbers, I take
>> sum of squares of the numbers centered on the number chosen.
>> If it is less than a certain constant, I will take the
>> average of the numbers chosen.  
>> 
>> Anyone can give me a sample code. You help will be greatly
>> appreciated.

   Y<-rep(NA,100) ##### This line is needed!
   x<-rnorm(100)
   const <-150
   for( i in (1:100) ) {if(sum(x-x[i])^2<const) Y[i]<-x[i]}
   Y[!is.na(Y)]
   [1]  0.17096364 -0.32720155  0.19542299  0.13363724
   [5] -0.19961480 -0.24486536 -0.31485802 -0.33369635
   [9]  0.09981291  0.04263151  0.11127977  0.12144595
  [13] -0.27767009 -0.01242218  0.06244776  0.11646301
 
   mean(Y[!is.na(Y)])
   [1] -0.04101397
 
> but I'm sure somebody out there will come up with a much
> more elegant solution!
> 
> Best wishes,
> Ted.
> 
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861  [NB: New number!]
> Date: 11-Nov-04                                       Time: 20:56:08
> ------------------------------ XFMail ------------------------------
> 
> ______________________________________________
> 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

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861  [NB: New number!]
Date: 11-Nov-04                                       Time: 21:23:33
------------------------------ XFMail ------------------------------




More information about the R-help mailing list