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

  • Home
  • SEARCH
  • 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 6762057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:16:06+00:00 2026-05-26T14:16:06+00:00

I have the following data frame: > str(df) ‘data.frame’: 3149 obs. of 9 variables:

  • 0

I have the following data frame:

> str(df)
'data.frame':   3149 obs. of  9 variables:
 $ mkod : int  5029 5035 5036 5042 5048 5050 5065 5071 5072 5075 ...
 $ mad  : Factor w/ 65 levels "Akgün Kasetçilik         ",..: 58 29 59 40 56 11 33 34 19 20 ...
 $ yad  : Factor w/ 44 levels "BAKUGAN","BARBIE",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ donem: int  201101 201101 201101 201101 201101 201101 201101 201101 201101 201101 ...
 $ sayi : int  201101 201101 201101 201101 201101 201101 201101 201101 201101 201101 ...
 $ plan : int  2 2 3 2 2 2 7 3 2 7 ...
 $ sevk : int  2 2 3 2 2 2 6 3 2 7 ...
 $ iade : int  0 0 3 1 2 2 6 2 2 3 ...
 $ satis: int  2 2 0 1 0 0 0 1 0 4 ...

I want to remove 21 specific rows from this data frame.

> a <- df[df$plan==0 & df$sevk==0,]
> nrow(a)
[1] 21

So when I remove those 21 rows, I will have a new data frame with 3149 – 21 = 3128 rows. I found the following solution:

> b <- df[df$plan!=0 | df$sevk!=0,]
> nrow(b)
[1] 3128

My above solution uses a modified logical expression (!= instead of == and | instead of &). Other than modifying the original logical expression, how can I obtain the new data frame without those 21 rows? I need something like that:

> df[-a,] #does not work

EDIT (especially for the downvoters, I hope they understand why I need an alternative solution): I asked for a different solution because I’m writing a long code, and there are various variable assignments (like a‘s in my example) in various parts of my code. So, when I need to remove rows in advancing parts of my code, I don’t want to go back and try to write the inverse of the logical expressions inside a-like expressions. That’s why df[-a,] is more usable for me.

  • 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-05-26T14:16:07+00:00Added an answer on May 26, 2026 at 2:16 pm

    You can use the rownames to specify a “complementary” dataframe. Its easier if they are numerical rownames:

    df[-as.numeric(rownames(a)),]
    

    But more generally you can use:

    df[setdiff(rownames(df),rownames(a)),]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data frame in R: > str(df) 'data.frame': 545227 obs. of
I have the following matrix (actually a data frame) in R: > str(x2) 'data.frame':
I have a large data frame with the following fields (example data). #dput(data) gives...
I have a data frame containing the following fields: a, b, c. a and
I have the following data frame z x y 1 1 a 2 2
i have the following data frame dd <- data.frame(b = c(High, Medium, Highest, Low,
Let's say I have the following data frame. dat <- data.frame(city=c(Chelsea,Brent,Bremen,Olathe,Lenexa,Shawnee), tag=c(rep(AlabamaCity,3), rep(KansasCity,3))) I
I have the following data frame: data.frame(a = c(1,2,3),b = c(1,2,3)) a b 1
Say I have the following R data.frame ZZZ : ( ZZZ <- structure(list(n =
I have the following question: I have data frame which looks like this. I

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.