Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 452

Compile two identical rows into one [closed]

$
0
0

I have my data combined_dt like following :

XIDdate_measureMonthAgecompiled_metrics
2520632016-12-281263.7258 NA
1327420632016-12-281263.7NA 2948

Instead of having

XIDdate_measureMonthAgeheightbody_mass
2520632016-12-281263.72582948

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


Viewing all articles
Browse latest Browse all 452

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>