Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`rows_update` Error: `x` key values are not unique

Tags:

r

dplyr

Is it possible to use rows_update with non-unique x values?

library(dplyr)

x = tibble(x = c(1,1,2), z = "x")
y = tibble(x = c(1,2), z = "y") 
   
rows_update(x, y)
#> Matching, by = "x"
#> Error: `x` key values are not unique.

Created on 2020-07-17 by the reprex package (v0.3.0)

like image 515
John-Henry Avatar asked Nov 01 '25 06:11

John-Henry


1 Answers

The issue is that rows_update requires key variables to take unique values. If the constraint is to use rows_update without creating extra-columns, I would propose:

x %>% distinct() %>% 
rows_update(y, by = "x") %>% 
right_join(x %>% select(x), by = "x")
like image 74
Roland Avatar answered Nov 03 '25 19:11

Roland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!