0

I know that the title could be a Little confussing, but basically this is what I want.

Lets supposse I have a a dataframe of this form

P_SEXO P_EDADR COD_ENCUESTAS
   <dbl>   <dbl>         <dbl>
1      2      16            74
2      2       9            75
3      2      18            75
4      2      11            75
5      2      11            76
6      2       1            76

As you can see, theres some values that repeats on COD_ENCUESTAS, this is because its like an índex in another dataframe (df2).

Df2 have a form like this:

COD_ENCUESTAS VA1_ESTRATO
          <dbl>       <dbl>
1           74          24
2           75          23
3           76          12
4           77           23
5           78           14
6           79          11

I want output:

P_SEXO P_EDADR COD_ENCUESTAS    VA1_ESTRTO 
   <dbl>   <dbl>         <dbl>   <dbl>
1      2      16            74    24
2      2       9            75    23
3      2      18            75    23
4      2      11            75    23
5      2      11            76    12
6      2       1            76    12

Thnaks beforehand -lasagna

lasagna
  • 135
  • 1
  • 10
  • 1
    Possible duplicate of https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right – akrun Jul 11 '22 at 19:45
  • 1
    simply do a left join between these two dataframe by `COD_ENCUESTAS` like `dplyr::left_join(df1, df2, by = "COD_ENCUESTAS") ` – shafee Jul 11 '22 at 19:48

1 Answers1

0

You can use left join of dplyr and tidyverse. Here is an example of the code you could use:

df <- df1 %>%
  left_join(df2, by="COD_ENCUESTAS")

df should be the dataframe you're looking for.

Best,

Léo Henry
  • 127
  • 10