cbind two different column lengths

the first dataframe contains duplicate values of a single observation which the column length is long, while the second dataframe contains identifiers or unique values which column lengh is shorter than the first data frame. so how we can combine or merge the two dataframes?
thank you in advance!!

You could use a join(). Here's an example.

library(dplyr, warn.conflicts = FALSE)

long_df <- data.frame(id = c("A", "A", "B", "A", "B"), 
                      value = c(30L, 10L, 5L, 20L, 15L))

short_df <- data.frame(id = c("A", "B"),
                       cat = c("Apple", "Banana"))

long_df %>% left_join(short_df, by = "id")
#>   id value    cat
#> 1  A    30  Apple
#> 2  A    10  Apple
#> 3  B     5 Banana
#> 4  A    20  Apple
#> 5  B    15 Banana

Created on 2020-04-27 by the reprex package (v0.3.0)

1 Like

thank you very much i satisfied by the answer

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.