I am trying to compare values on data frame rows, and removing all the ones that match, with this
dat[!dat[1]==dat[2]]
where
> dat
returns
n1 n2
n1 n4
n4 n5
n1 n3
n4 n4
So i want it to compare the values and delete the last row, since both columns have the same data. But when i use the above code, it tells me
Error in Ops.factor(left, right) : level sets of factors are different
the str(dat) reads
'data.frame': 5 obs. of 2 variables:
$ V1: Factor w/ 2 levels "n1","n4": 1 1 2 1 2
$ V2: Factor w/ 4 levels "n2","n3","n4",..: 1 3 4 2 3
I suspect in the creation of your data, you inadvertently and implicitly converted your columns to factors. This possibly happened when you read the data from source, e.g. when using
read.csvorread.table. This example illustrates it:The remedy is to pass the argument
stringsAsFactors=FALSEtoread.table():Then your code works (except that I suspect you’ve missed a comma):