79113468

Date: 2024-10-22 10:02:35
Score: 0.5
Natty:
Report link

Eventually, I got it but my solution requires more lines of code. Thank you very much to anyone who has provided a solution and I apologies again for the confusion between the first post and the definitive one.

Stef

myrows.in <- list()
myrows.out <- list()

for (i in c(1:3)){
myrows.in[[i]] <- match(mydf.empty$age,mydf.list[[i]]$age)
myrows.out[[i]] <- match(mydf.list[[i]]$age,mydf.empty$age)
}
myrows.in
myrows.out

#creating an empty list of dataframe
mydf.empty <- 
data.frame(age=factor(0:14,levels=c(0:14),ordered=TRUE),Freq=c(rep(0,15)))
mydf.out.list <- list()
for (i in c(1:3)){
mydf.out.list[[i]] <- mydf.empty
}
mydf.out.list

#filling the empty list of dataframe
for (i in c(1:3)){
mydf.out.list[[i]]$Freq[unlist(myrows.out[i])] <- 
mydf.list[[i]]$Freq[na.omit(unlist(myrows.in[i]))] 
}
mydf.out.list
identical(myout.list[1],mydf.out.list[1])
identical(myout.list[2],mydf.out.list[2])
identical(myout.list[3],mydf.out.list[3])
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: stefano