Here's a solution that uses dplyr. First, I create a toy data frame. (For future questions, it's easier for us if you post copy-and-pasteable data rather than an image. dput is useful for this.)
df <- data.frame(patient_id = c(1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4),
blood_pressure = sample(90:134, 12, replace = TRUE))
which looks like this:
# patient_id blood_pressure
# 1 1 130
# 2 1 130
# 3 1 128
# 4 2 109
# 5 2 91
# 6 3 95
# 7 3 129
# 8 4 134
# 9 4 116
# 10 4 101
# 11 4 131
# 12 4 112
Next, I load the required library.
library(dplyr)
Then, I group by patient_id, add a variable called order using the mutate function, which is the row number within each group given by the row_number function, and finally ungroup the result.
df %>%
group_by(patient_id) %>%
mutate(order = row_number()) %>%
ungroup
giving,
# patient_id blood_pressure order
# <dbl> <int> <int>
# 1 1 130 1
# 2 1 130 2
# 3 1 128 3
# 4 2 109 1
# 5 2 91 2
# 6 3 95 1
# 7 3 129 2
# 8 4 134 1
# 9 4 116 2
# 10 4 101 3
# 11 4 131 4
# 12 4 112 5