You should cc r-help on all correspondence, so others can follow the thread.
Here is a very simple example of a home-made smooth function. Perhaps you can modify it to suit your needs. Jean # simple smooth function, using a weighted mean smoothfunction <- function(allxs, allys, centerindex, halfwidth) { distfromcenter <- abs(allxs - allxs[centerindex]) weight <- ifelse(distfromcenter <= halfwidth, 1/(distfromcenter+1), 0) weighted.mean(allys, weight) } # fake data x <- runif(1000) y <- 3*x^2 + x + rnorm(1000) # set desired halfwidth of window for smooth halfwid <- 0.1 # determine the smoothed value of y for each value of x L <- length(x) smoothedy <- numeric(L) for(i in 1:L) { smoothedy[i] <- smoothfunction(x, y, i, halfwid) } # plot the results plot(x, y) lines(x[order(x)], smoothedy[order(x)], lwd=3) On Wed, Nov 13, 2013 at 5:59 PM, umair durrani <umairdurr...@outlook.com>wrote: > *Thanks Jean....at-least someone replied. I have gone through the link you > provided but the real problem is that it is more complex to understand > than the R documentation. Actually, I don't have any background in noise > reduction / smoothing of data. Can you guide me how I could just apply the > equation included in my question?* > > *best regards,* > *Umair Durrani* > *email: umairdurr...@outlook.com <umairdurr...@hotmail.com>* > > > ------------------------------ > From: jvad...@usgs.gov > Date: Wed, 13 Nov 2013 15:10:07 -0600 > Subject: Re: [R] How to sum a function over a specific range in R? > To: umairdurr...@outlook.com > CC: r-help@r-project.org > > > > On Tue, Nov 12, 2013 at 11:45 AM, umair durrani > <umairdurr...@outlook.com>wrote: > > I am new to R and have already posted this question on stack overflow. The > problem is that I did not understand the answers as the R documentation > about the discussed functions (e.g. 'convolve') is quite complicated for a > newbie like me. Here's the question: > I have a big text file with more than 3 million rows. The following is the > example of the three columns I want to use: > indx vehID LocalY > 1 2 35.381 > 2 2 39.381 > 3 2 43.381 > 4 2 47.38 > 5 2 51.381 > 6 2 55.381 > 7 2 59.381 > 8 2 63.379 > 9 2 67.383 > 10 2 71.398 > where,indx = IndexvehID = Vehicle ID (Here only '2' is shown but infact > there are 2169 vehicle IDs and each one repeats several times because the > data was collected at every 0.1 seconds)LocalY = The y coordinate of the > vehicle at a particular time (The time column is not shown here) > What I want to do is to create a new column of 'SmoothedY' using the > following formula: > SmoothedY = 1/Z * Summation from (i-15) to (i+15) (LocalY * > exp(-abs(i-k))/5)) > where,i = indxZ = Summation from (k =i-15) to (k = i+15) ( > exp(-abs(i-k))/5)) > How can I apply this formula to create the new column 'SmoothedY'? This is > actually a data smoothing problem but default smoothing algorithms in R are > not suitable for my data and I have to use this custom formula. > Thanks in advance. > > Umair Durrani > > > I have never tried this myself, but it appears as if you can define your > own smoothing function using Simon Wood's mgcv package. Check out > http://www.maths.bath.ac.uk/~sw283/talks/snw-R-talk.pdf for more > information. > > Jean > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.