[R] Apply a shift which is a function of the array.

Jim Hargreaves james at ipec.co.uk
Fri Jul 2 13:05:24 CEST 2010


Dear List,

I have a 2,000x10,000 array of time domain data which when plotted draws 
a distinct pulse. The matrix is 10,000 pulses of length 2000. I would 
like the pulse to be shifted so that the peak (which.max of the pulse 
data) is consistently at point 400.

I don't want to use loops as it'll take a long time. The problem with 
using apply is the pulse peak varies for each pulse, so I want to use 
something like:

apply(really_mean_pulse, 2, shift, which.max(really_mean_pulse))

(Using the shift function from the "magic" library)

This doesn't work, so I need to modify this so that the argument to 
shift is dependent on the column the shift is being applied to.

Any suggestions would be greatly appreciated!

Kind Regards,
Jim Hargreaves



More information about the R-help mailing list