Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:50:11+00:00 2026-06-06T02:50:11+00:00

I am trying to compare values on data frame rows, and removing all the

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:50:13+00:00Added an answer on June 6, 2026 at 2:50 am

    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.csv or read.table. This example illustrates it:

    dat <- read.table(text="
    n1  n2
    n1  n4
    n4  n5
    n1  n3
    n4  n4")
    
    str(dat)
    '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
    

    The remedy is to pass the argument stringsAsFactors=FALSE to read.table():

    dat <- read.table(text="
    n1  n2
    n1  n4
    n4  n5
    n1  n3
    n4  n4", stringsAsFactors=FALSE)
    
    str(dat)
    'data.frame':   5 obs. of  2 variables:
     $ V1: chr  "n1" "n1" "n4" "n1" ...
     $ V2: chr  "n2" "n4" "n5" "n3" ...
    

    Then your code works (except that I suspect you’ve missed a comma):

    dat[!dat[1]==dat[2], ]
      V1 V2
    1 n1 n2
    2 n1 n4
    3 n4 n5
    4 n1 n3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compare two arrays and get only the values that exist on
I was trying to compare with the cube's data with that of data mart
I am trying to compare two tables to find rows in each table that
I have a script that is trying to compare specific data based on a
Trying to compare and print only members with Inactive status. The problem is that
This is what I am trying to achieve: DataTable populated using data from non
I am trying to get all values (except corresponding to a particular key) from
I'm trying to store randomly generated dice values in some data structure, but don't
I'm trying to compare a couple of array values stored in a flat file
I am trying to test the likelihood that a particular clustering of data has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.