0

I'm trying to 'bin' numbers which are beats per minute (BPM) into heart rate; the number of BPMs per time. I'm trying to keep the most similar consecutive numbers together as 1 heart rate. For example, if the BPM was

x <- c(15.1, 15.2, 15.3, 20.1, 20.2, 20.3)

over 6 seconds (each BPM is an average for that second), I'd like to interpret this as 2 heart rates per 6 seconds.

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Quigg
  • 11
  • 1
  • 2

1 Answers1

1

Using your example. You define and play with cut to define the breaks you want and then table to create a frequency table with the occurrences for each group.

hr <- c(15.1, 15.2, 15.3, 20.1, 20.2, 20.3)
groups<- cut(hr,breaks = 2)
as.data.frame(table(groups))

Output:

       groups Freq
1 (15.1,17.7]    3
2 (17.7,20.3]    3
mpalanco
  • 12,960
  • 2
  • 59
  • 67