Entering edit mode
2.7 years ago
Mgs3
▴
30
Greetings, I have a dataset as such:
countdata<-fread("table.txt",data.table=F)
countdata
A1 B1 Country
11465 7 AT
12323 6 AT
21321 6 BT
21311 7 CT
12321 8 CT
I need to extract unique values of each column, output desired for the Country column
Country
AT
BT
CT
I managed to do that with the distinct() function of dplyr. My issue is when I try to input a variable, for instance
> condition = "Country"
> uni <- distinct(countdata, condition)
Error in `distinct_prepare()`:
! `distinct()` must use existing variables.
✖ `Condition` not found in `.data`.
Following other posts i tried with !! or {{ }} unsuccesfully:
> condition = "Country"
> uni <- distinct(countdata, !!condition)
> uni
"Country"
1 Country
>
> uni <- distinct(countdata, {{condition}})
> uni
"Country"
1 Country
quoteless <- noquote(condition)
> uni <- distinct(countdata, !!quoteless)
> uni
<noquote>
1 Country
How can i solve this issue?
You can try this pattern:
Hope to help.