I have my data combined_dt like following :
X | ID | date_measure | Month | Age | compiled_metrics |
---|---|---|---|---|---|
25 | 2063 | 2016-12-28 | 12 | 63.7 | 258 NA |
13274 | 2063 | 2016-12-28 | 12 | 63.7 | NA 2948 |
Instead of having
X | ID | date_measure | Month | Age | height | body_mass |
---|---|---|---|---|---|---|
25 | 2063 | 2016-12-28 | 12 | 63.7 | 258 | 2948 |
Compile_metrics is in character.
I have tried this code but then the output is completly messy, i don't know why...
#first tablecombine_height_body_mass <- function(df) { df %>% group_by(ID) %>% slice_max(order_by = date_measure) %>% mutate(combined_metrics = paste(height, body_mass)) %>% select(all_of(c("X","ID","date_measure","Month","Age","height", "body_mass")))}final_df <- combine_height_body_mass(combined_dt)#Compile rowscombine_height_body_mass <- function(df) { combined_df <- df %>% group_by(ID) %>% slice_max(order_by = date_measure) %>% select( X, ID, date_measure, Month, Age, height, body_mass ) combined_df <- combined_df %>% mutate(compiled_metrics = paste(height, body_mass)) return(combined_df)}final_df <- combine_height_body_mass(combined_dt)
PS: height and body_mass should be numeric
Thanks