val
val

Reputation: 1699

R - unique() gives 'incomparables != FALSE' error

I have a (11590 x 2) df with two factor variables (values, ind), as follows:

> head(df)
          values  ind
8632   acanthite X138
40132  acanthite X638
1     actinolite   X1
1387  actinolite  X23
1765  actinolite  X29
1891  actinolite  X31

When I try to get all the unique values, why do I get the following error? How should I get around this error to get a df with only the records for unique values? Any help would be appreciated.

> unidf<-unique(df,"values")
Error: argument 'incomparables != FALSE' is not used (yet)

Upvotes: 6

Views: 9950

Answers (2)

Randcelot
Randcelot

Reputation: 56

If you want a tidyverse friendly solution you can also replace unique with dplyr::distinct and your code as it stands should also work.

You could use:

library(dplyr)
unidf <- distinct(df,values)

Upvotes: 3

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521389

R is interpreting the second parameter to your call to unique() as the value of incomparables. Your call is being interpreted as this:

unidf<-unique(df, incomparables="values")

If you want to get unique rows from your data frame using only the values column then try this:

unidff <- df[!duplicated(df$values), ]

Upvotes: 11

Related Questions