I'm often working with data frames in R where different parameters have multiple measurements recorded at various time points for each individual. So far, I have repeated the "constant" parameters such as age and gender on each row for the same individual, but somehow it seems a little trivial to repeat the same information again and again.
Basically, I would like become able to fetch and "merge" information from two data frames, for instance when fitting a model such as:
glm(hormone_level ~ time_point + age + gender, random = ~ 1 | patient_id)
hormone_level
and time_point
should then be fetched from data frame 1, while age
and gender
should be fetched from data frame 2 (see below).
I'm not sure whether I am looking for information on lists, or if it is better to use functions to merge the relevant information from the two data frames to make a third. Do you know a place where I can find more information on this topic, preferably with some useful examples?
Data frame 1:
patient_id time_point hormone_level
001 1 55
001 2 85
001 3 105
002 1 48
...
Data frame 2:
patient_id age gender
001 30 M
002 45 F
003 32 F
...