Is there a way to make the "findpeaks" function run faster on a large dataset?

Viewed 69

I have a large dataset called "endata" - 5.9 million data points. This represents data over a 90 day period. The dataset is a single vector. The first five data points look something like this:

0.0171365458527622 0.0174577280551263 0.0177808003184100 0.0181056613918160 0.0184322165779018 0.0187603772480992

I would like to use the "findpeaks" function from the pracma package. This is a line of code that I would like to use:

y <- data.frame(findpeaks(-endata,minpeakdistance=10, nups=1, ndowns=1, npeaks=Inf, minpeakheight = -0.5, sortstr=FALSE))

The function takes a long time (hours) to run. Is there any way to make the function run faster? I have already tried splitting the dataset by individual days but this makes the output difficult to manage.

1 Answers

You can use parallel computing in R to speed this up. Vary cores= to suit your machine.

library(doMC)
registerDoMC(cores = 5)

y <- data.frame(findpeaks(-endata,minpeakdistance=10, nups=1, ndowns=1, 
                npeaks=Inf, minpeakheight = -0.5, sortstr=FALSE))

registerDoSeq()
Related