r - No applicable method for 'anti_join' applied to an object of class "factor" -
i want identify rows present in dataframe1 not present in dataframe2 based on particular column. have used below code desired information.
diffid <- anti_join(dat$id,datwe$id)
unfortunately, have encountered error:
error in usemethod("anti_join") :
no applicable method 'anti_join' applied object of class "factor"
i have checked class of desired column in both dataframes , turned out factor
. have tried separate column separate variable in assumption might solve issue, of no luck !
fac1 <- datwe$id fac2 <- dat$id diffid <- anti_join(fac2,fac1)
could please share thoughts ?
thanks
almost dplyr
functions operate on tbls
(depending on context can data.frame
, data.table
, database connection , on) want this:
> dat <- data.frame(id=c(1, 3, 6, 4), x=runif(4)) > datwe <- data.frame(id=c(3, 5, 8), y=runif(3)) > anti_join(dat, datwe, by='id') %>% select(id) id 1 4 2 6 3 1
note ordering not preserved.
if use factors (unlike numerics in example above) different levels there conversion between factor
, character
involved.
if want operate on vectors can use setdiff
(available in both base
, dplyr
)
> setdiff(dat$id, datwe$id) [1] 1 6 4
Comments
Post a Comment