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 9172883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:27:35+00:00 2026-06-17T16:27:35+00:00

I have a data frame set up with one column as a factor with

  • 0

I have a data frame set up with one column as a factor with several levels. I’d like to extract rows that do not have a unique value for that column (i.e. the level is present in multiple rows).

So for some simple test data:

factor dat1 dat2 dat3
     a  1.0  1.0  1.0
     a  1.0  0.9  1.0
     b  0.9  0.8  0.6
     c  0.9  1.0  0.0

I’d like to retain only the first two rows. What is the best way to do this? Preferrably I’d like to make more general queries, i.e. extract rows for levels of the factor present in at least 3 rows, exactly 2 rows, etc.

  • 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-17T16:27:36+00:00Added an answer on June 17, 2026 at 4:27 pm

    Here’s a solution with table (assuming the data frame’s name is df):

    nRows <- 2 # minimum number of occurrences
    
    tab <- table(df$factor) # count
    
    df[df$factor %in% names(tab)[tab >= nRows], ] # extract rows
    

    If you want to use an exact criterion instead, change >= to ==.

    The result:

      factor dat1 dat2 dat3
    1      a    1  1.0    1
    2      a    1  0.9    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame where one particular column has a set of specific
Suppose that we have a data frame that looks like set.seed(7302012) county <- rep(letters[1:4],
I have a data frame like below (20,000 rows by 49 cols). Each row
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a set of data that looks like this, species<-ABC ind<-rep(1:4,each=24) hour<-rep(seq(0,23,by=1),4) depth<-runif(length(ind),1,50)
I have a dataset that looks a little like this: a <- data.frame(x=rep(c(1,2,3,5,7,10,15,20), 5),
I have a data set which looks something like data<-c(0,1,2,3,4,2,3,1,4,3,2,4,0,1,2,0,2,1,2,0,4) frame<-as.data.frame(data) I now want
I have a data frame where one column is species' names, and the second
I have data frame with some numerical variables and some categorical factor variables. The
I have a data frame that's about ts1[100, 2000] in dimension as follows: >

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.