[R] How to sum a function over a specific range in R?

Bert Gunter gunter.berton at gene.com
Thu Nov 14 00:10:34 CET 2013


?filter

perhaps.

-- Bert

On Wed, Nov 13, 2013 at 1:10 PM, Adams, Jean <jvadams at usgs.gov> wrote:
> On Tue, Nov 12, 2013 at 11:45 AM, umair durrani <umairdurrani at 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 at 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374



More information about the R-help mailing list