Eu tenho dois dataframes com colunas e tamanhos de linhas diferentes
library(tidyverse)
tb1 <- tibble(id= 1:10,
a= 1:10,
b=11:20)
tb2 <- tibble(id= 1:5,
q= 1:5,
z= 11:15)
Posso combiná-los facilmente por id
chave
full_join(tb1, tb2, by = "id")
.
# A tibble: 10 x 5
id a b q z
<int> <int> <int> <int> <int>
1 1 1 11 1 11
2 2 2 12 2 12
3 3 3 13 3 13
4 4 4 14 4 14
5 5 5 15 5 15
6 6 6 16 NA NA
7 7 7 17 NA NA
8 8 8 18 NA NA
9 9 9 19 NA NA
10 10 10 20 NA NA
Como posso fazer o mesmo se não tenho uma coluna com chave e não quero criá-la antecipadamente em cada dataframe.
tb1 <- tibble(a= 1:10,
b=11:20)
tb2 <- tibble(q= 1:5,
z= 11:15)
existe alguma solução elegante? Não tão volumoso assim
tb1 %>%
mutate(row = row_number()) %>%
left_join(
tb2 %>% mutate(row = row_number()),
by = "row"
) %>%
select(-row)
Tente
merge
, mas isso não é recomendado.Especificando
by=0
mesclagens nos nomes de linhas .