0

Hi I have two data frames

Data frame a

enter image description here

Data frame b

enter image description here

I want put the food column in dataframe a from b based on animal name and if the animal name is not there it should come as NA This is what I am expecting

enter image description here

was trying with merge function in R but getting error

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • What code did you try with `merge`? `merge(a, b, by = 'Animal', all.x = TRUE)` should work for your data. – Ronak Shah Oct 18 '20 at 10:10
  • Hi Ronak , actually this is just an example what i put here how can i specifically mention column food in the code , what i am trying is of a huge dataset having 1000 columns and above code will merge the entire dataframe – Manish Mukherjee Oct 18 '20 at 10:38
  • You can select the columns that you want to merge. `merge(a, b[c('food', 'Animal')], by = 'Animal', all.x = TRUE)` – Ronak Shah Oct 18 '20 at 10:41

0 Answers0