The other answers have provided a number of methods for calculating the mean across groups. A related post provides a number of methods for calculating group level maxima. You would need to replace max
with mean
in these answers.
Here is an additional method for reshaping wide using the base R function reshape
.
Use the data.frame provided by @jaap, add a variable for counting the observations by ID:
df$times <- ave(df$bp, df$id, FUN=seq_along)
Now, perform the reshape, dropping the unwanted date variable:
reshape(df, direction="wide", drop="date", timevar="times")
id bp.1 bp.2 bp.3
1 1 120 134 129
4 2 110 124 119