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. Peter [[alternative HTML version deleted]]
Please read the posting guide that tells you to a) use a meaningful subject line b) give a reproducible example if you can c) read the manuals and help files first If you have a vector (not a list) of numbers, say x, and you want to center it on the median you can do x <- c(1,2,3,4,5) Then x - median(x) will give you the deviation of x from its median. Note that operations in R is vectorised, so you do not need to to do something like "for(i in 1:5) y[i] <- x[i] - median(x)". Next you want to square this deviation and sum over all elements. d <- x - median(x) sum( d^2 ) Or you can do it in one line as "sum( (x - median(x))^2 )" On Thu, 2004-11-11 at 16:28, 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. > > > > Peter > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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-- Adaikalavan Ramasamy ramasamy at cancer.org.uk Centre for Statistics in Medicine http://www.ihs.ox.ac.uk/csm/ Cancer Research UK Tel : 01865 226 677 Old Road Campus, Headington, Oxford Fax : 01865 226 962
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. > > PeterLet X = (x1, x2, ... , xn} be your list of numbers. It seems that what you are looking for is the mean of the set Y: Y = {y1, y2, ... , ym} such that, for each yj, yj is in X and sum[over i]( (xi - yj)^2 ) < const Is this right? If so, you can do it straightforwardly with a loop, like: 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 ------------------------------
Hi, see: http://agec221.agecon.uiuc.edu/csiss/Rgeo/ for R-Spatial Models, are there many packages for spatial data analysis. Regards Vito you wrote: I need information about space state models in structural model and kalman filtering. I have a univariate time serie and i nedd aplicate space state model Thank's ====Diventare costruttori di soluzioni Became solutions' constructors "The business of the statistician is to catalyze the scientific learning process." George E. P. Box Top 10 reasons to become a Statistician 1. Deviation is considered normal 2. We feel complete and sufficient 3. We are 'mean' lovers 4. Statisticians do it discretely and continuously 5. We are right 95% of the time 6. We can legally comment on someone's posterior distribution 7. We may not be normal, but we are transformable 8. We never have to say we are certain 9. We are honestly significantly different 10. No one wants our jobs Visitate il portale http://www.modugno.it/ e in particolare la sezione su Palese http://www.modugno.it/archivio/palese/