issues assigning ids in a tibble

Hello,
I have a tibble like this one named "nodes" with an "id" column and i have another one similar but only with the labels, it's a subset and i would like to add the ids to this other tibble from the nodes tibble.
Could anyone help me please.
Thank you!!!!

nodes
#> # A tibble: 34 x 4
#> id label x y
#>
#> 1 1 AT 47.5 14.5
#> 2 2 BE 50.8 4.40
#> 3 3 BG 42.7 24.2
#> 4 4 CH 46.9 7.46
#> 5 5 CY 35.0 33.2
#> 6 6 CZ 50.0 14.5
#> 7 7 DE 50.7 10.4
#> 8 8 DK 55.3 10.5
#> 9 9 EE 58.9 25.2
#> 10 10 ES 40.3 3.70
#> # ... with 24 more rows

Here is an example of using inner_join() from the dplyr package to add the id column to the second data set.

DF <- data.frame(id = 1:3, label = c("AT", "BE", "BG"), x = c(6,5,7), y = c(0,8,9))
DF2 <- data.frame(label = c("BE", "BG", "AT"), x = c(6.8,5.8,7.8), y = c(0.8,8.8,9.8))
DF2
#>   label   x   y
#> 1    BE 6.8 0.8
#> 2    BG 5.8 8.8
#> 3    AT 7.8 9.8
library(dplyr, warn.conflicts = FALSE)
DF2 <- inner_join(DF2, select(DF,id, label), by = "label")
DF2
#>   label   x   y id
#> 1    BE 6.8 0.8  2
#> 2    BG 5.8 8.8  3
#> 3    AT 7.8 9.8  1

Created on 2020-11-27 by the reprex package (v0.2.1)

Thank you very much!!!!!

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.