1

Here is my file:

blood pressure data every second

time3 is going from around -3600 to +400-600ms. I need to bin this time3 in 20 seconds window with the 0 time point staying as 0 and not being in the middle of a window. Then I need to do a mean of reSYS for each 20 sec windows. I need to do this for each Subject ("DL001" to "DL028") and each condition ("Light" or "control").

I tried several options, the closer one is this one:

data3 <- data2 %>% 
  group_by(time3 = cut(time3, breaks=205, include.lowest = TRUE)) %>%
  summarize(RR_int.mean = mean(RR_int))

But the 20 sec window start with the first time point that appears -3599.312 and goes all the way up, such that the 0 time point is in a window between -9 and +11. It average all the values from all the subjects together as well instead of doing it for each subject separately.

Can someone help me?

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
Virginie
  • 67
  • 5
  • Don't post data as images. Please edit **the question** with the output of `dput(df)`. Or, if it is too big with the output of `dput(head(df, 20))`. (`df` is the name of your dataset.) – Rui Barradas Sep 12 '18 at 17:45
  • If you want a mean of `reSYS` then why `mean(RR_int)`? – Rui Barradas Sep 12 '18 at 17:53

1 Answers1

0

It's difficult to say without an example dataset but try the following.

Define a breaks vector that includes the zero and goes up or down from there.

brk_time3 <- with(data2, unique(c(rev(seq(0, min(time3), by = -20)), seq(0, max(time3), by = 20))))

Now it's a simple group_by/summarize.

data3 <- data2 %>%
    group_by(time3 = cut(time3, breaks = brk_time3, include.lowest = TRUE), Subject, condition) %>%
    summarize(mean.reSYS = mean(reSYS))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66