0

I have two datasets: mydata2 and mydata3

Mydata2: I want 2 columns in it: Destination.DisplayName and Partner.Type

(Partner.Type is based off Destination.DisplayName)

Mydata3: 2 columns in it: If and Then

I need a line of code that tests if Destination.DisplayName is equal to If, and if it is, set partner.type to the value in Then

Right now this is what I have

mydata2$Partner.Type[  mydata2$Destination.DisplayName %in% mydata3$If] = as.character((mydata3$Then[match(mydata2$Destination.DisplayName, mydata3$If)]))

Link to mydata2 = mydata2 Link to mydata3 = mydata3

joran
  • 169,992
  • 32
  • 429
  • 468
Jon Pop
  • 33
  • 6
  • 1
    Look into `merge` and/or `match`. This is a pretty poor question, by the way. Much better to come up with a minimal, self-contained example, including desired output, as explained here: http://stackoverflow.com/a/28481250/ – Frank Sep 17 '15 at 18:21
  • I use the match function in my line of code but I can not see what is wrong with it. – Jon Pop Sep 17 '15 at 18:55
  • Oh, didn't notice that there. In any case, yeah, you'll probably get better help by posting a [mcve] – Frank Sep 17 '15 at 18:57
  • I attached both data sets and indicated the problem I am having with a line of code that I have tried before. What am I missing from here? – Jon Pop Sep 17 '15 at 18:59
  • You are missing the "minimal" part. In the process of creating a minimal example, the odds are very good that you'll solve your problem yourself, but if you don't then you can ask it here and it'll be very easy for folks to help. Read the last link for an idea of the recommended approach. Simply dumping your actual application (especially via external links) isn't taken well here. We only want questions that will still be of value to others who come across it in the future (so -- simple, easy to understand, no dead links, etc.). – Frank Sep 17 '15 at 19:02

0 Answers0