How to paste rows to a variable based on specific value of another variable

Hey,
I'm currently using dyadic data (collecting data from children and their mothers- i.e. did.x.x is the name of each dyad, and id is for each individual - for example, first individual is mother #11020, and after is child #12020- both are part of dyad #20).

I'm using the variables tw_child_wave and tw_child_overall as outcomes but both are taken from the mother's reports only. Thus, for each child I want to paste the same value of their mother (i.e. for id 12020, instead of "NA", the tw_child_wave and tw_child_overall should be 0.6666667 and 0.7228916, respectively, and so on).

I'm struggling finding a way to to this with mutate of ifelse functions. Any ideas?
Thanks!

seems like you might be trying to do this :

library(tidyverse)

(df_1 <- data.frame(
  group=rep(1:2,each=2),
  val1=c(0.6,NA,.4,NA),
  val2=c(0.3,NA,.1,NA),
  memberid = 1:4
)) 

df_1 |> 
  group_by(group) |> 
  fill(val1,val2,.direction = "down")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.