2
votes

I have 3000 people in a dataset, each of them have Heart rate as a time-series. the time series interval is of 24 hours and in each hour there is max of 6 values, makes it max total of 24*6=144 values for each person (there is usually less). for every person I want to extract the number of "peeks" he has in the time interval.

I have checked and didn't find any function the calculate or give back more then the "absolute min/max" of the interval.

I have add an example of what I need, in the below graph although there is one absolute min and max, I need the whole four points (2 max and 2 min).

I really don't know how to extract this expect of creating my one function and using a lot of for-loops which isn't good.

can you help?

example

sample of the time-series:

dput(hr[1:20,])

structure(list(ID = c(5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 
5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 
5983L, 5983L, 5983L, 5983L, 5983L), Heart.Rate = c(103L, 109L, 
109L, 109L, 111L, 111L, 120L, 122L, 125L, 62L, 73L, 84L, 92L, 
97L, 98L, 101L, 105L, 105L, 106L, 106L), Time = structure(c(1077080040, 
1077083640, 1077084000, 1077084240, 1077083040, 1077085440, 1077082440, 
1077081240, 1077081840, 1077086640, 1077087240, 1077084900, 1077080700, 
1077080400, 1077086040, 1088496000, 1088494680, 1088495280, 1088498280, 
1088504880), class = c("POSIXct", "POSIXt"), tzone = "UTC")), .Names = c("ID", 
"Heart.Rate", "Time"), row.names = c(NA, 20L), class = "data.frame")
1
How did you get your smooth plot? Plotting this data does not give that picture.G5W
@G5W It just an illustrated example to explain what I need, that's it.user7307305

1 Answers

0
votes

What you want is finding inflation points (local extremums)

You may want to check this package. I used it occasionally and it was really useful.

Also you may want to check this post;

As it says there, you want to find the point that the sign of change in y (heart rate) changes.

In reference to there, this should work for you:

infl <- c(FALSE, diff(diff(Heart.rate)>0)!=0)