-3

I've created a data frame to store the information for 100 texts. And for each text, there are 10 rows. So there are total 1000 rows for this data frame. E.g.,

  text name        text id

----------------------------------

1.  A                1      
2.  A                2
3.  A                3
...
10. A                10  
11. B                1    
12. B                2
...
20. B                10
...

And I have metadata for these texts in an excel spreadsheet, but I only have one row for each text. So, there are 100 rows in this dataset. It looks like this:

File Name     Author    Gender   Age
---------------------------------------
 A            Adam       male    48
 B            Brown      male    30
 C            Cindy      female  30
 D            Donaldd    female  20

Now, I want to create a new data frame so that I can join the metadata (say Gender) to every texts in the first data frame. Anyone has any idea to do this?

Thanks!

PKumar
  • 10,971
  • 6
  • 37
  • 52
WeiWei
  • 1
  • 2
  • 1
    Please take full power of formatting capabilities of stackoverflow and perhaps read up on how to [make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Roman Luštrik Jun 30 '18 at 15:04
  • I'm confused about formatting in stackoverflow. Thanks for providing the link, it really helps! – WeiWei Jun 30 '18 at 15:20

1 Answers1

0

You can try matching the value of the information for each text in the metadata (DF_2) to the first data frame (DF_1)

DF_1$Gender <- with(DF_2, Gender[match(DF_1$`text name`, DF_2$`File Name`)])

This should produce:

text name        text id     Gender

----------------------------------

1.  A                1      male
2.  A                2      male
3.  A                3      male   
...
10. A                10     male  
11. B                1      male    
12. B                2      male
...
20. B                10     male
...
Elli
  • 13
  • 2