Suppose I have a dataframe:
> my.df <- data.frame(uid=c(1,1,3),somevalue=c("x","y","z"))
> my.df
uid somevalue
1 1 x
2 1 y
3 3 z
I want:
uid somevalue
1 1 y
2 3 z
I can't use
distinct(my.df, uid, .keep_all= TRUE)
because the variable name "uid" could change. However I have the variable name stored as a string.
So I get
> iKey <- "uid"
> distinct(my.df, iKey, .keep_all= TRUE)
uid somevalue
1 1 x
2 1 y
3 3 z
Warning message:
Trying to compute distinct() for variables not found in the data:
- `iKey`
This is an error, but only a warning is raised for compatibility reasons.
The operation will return the input unchanged.
How can I get distinct() to use the value of iKey and not take it literally?
distinctwill return 1st value of duplicate. Seedistinct(my.df, uid, .keep_all= TRUE)which isxforuid = 1. Do you want to return the last value of duplicate i.eyinstead ?