0

Long time reader, first time writer :) I have a long list of names and I need to create a loop that essentially puts a value in a column in one df (df1), but each name has a specific value associated with it. I have these values in a different data frame (df2). This is what I have so far and can't figure it out.

for (i in 1:df$Name){ df1$value[i]=df2$value }

but it only takes my list in df2 and copies it into df1$value column. The values dont actually match up with the name it is supposed to be assigned to. Thank you!

  • 1
    It sounds like you want to do a join, but it's kind of hard to tell without a clear reproducible example. – Axeman Apr 06 '23 at 22:11
  • Something like `merge(df1, df2, by = "Name")`? – Martin Gal Apr 06 '23 at 22:11
  • Yep, that works well enough for me! Thank you so much! I think i was overthinking it. You rock! – user21584544 Apr 06 '23 at 22:18
  • 1
    Most situations in which you have information in one table that needs to go into another table, a join is the easiest solution. It comes up all the time. Good luck! – Axeman Apr 06 '23 at 22:19

0 Answers0