If general you'll have to do it with two ifelse functions inside the mutate. Or even better use dplyr::case_when which is much more flexible. If your conditional boolean expression is complicated you could calculate this first
df%>%
arrange(id,drugclass, start_date, end_date)%>%
group_by(id,drugclass)%>%
mutate(
cond = row_number == 1, # do it like this for complex conditions
a1 = case_when(
cond ~ a3,
TRUE ~ a5 # otherwise
),
a2 = case_when(
cond ~ a4,
TRUE ~ a6 # otherwise
)
)