0

thank you for trying to help me out.

I have two dataframes and between the two there is a variable that is the same, the name of the products, I would like to take a column from a dataframe and copy it to the other one, however obviously the observation depend on the name of the product. The two datasets are not equal in size one has 2120 observations (where I want to paste the column) and the other 1480 observations (where the column is).

I am using DPLYR by the way

I haven't really tried anything but I would imagine something like this:


    for(vdixg$vendido(these column doesn't exist) in vdixg){
      if(vdixg$producto == dff$producto){
        vdixg$vendido == dff$vendido
        }
      }

However I'm pretty confident that this doesn't work because it doesn't take into consideration where the value is located and it doesn't have specify what happens in the case where a product that appears on one list isn't in the other although it might be something like:

    elseif(vdixg$producto != dff$producto){
      vdixg$vendido == 0)}

but I'm not sure

KingP
  • 3
  • 1
  • It sounds like you might want to try a `merge` or a `join`. But it's difficult to help more unless you share [some reproducible data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), in plain text, from `vdixg` and `dff`. – neilfws Nov 10 '22 at 23:58
  • See this question on how to merge in values: [How to join (merge) data frames (inner, outer, left, right)](https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right) – zephryl Nov 11 '22 at 00:18
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems. One way of doing this is by using the `dput` function. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Nov 15 '22 at 02:25

0 Answers0