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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:35:19+00:00 2026-05-23T09:35:19+00:00

Suppose I have a data frame, df with 30 columns: A1 to A30 .

  • 0

Suppose I have a data frame, df with 30 columns: A1 to A30. I know that I can subset this data frame by writing a command like:

 filteredrows = subset(df, A1 == 30 & A2 == 2 & A3 == "this")

The above example filters data based on values in three columns, but I have to do this for values in about say 12 columns. Writing those 12 values in the subset() function will make it too long. To make the code cleaner, is there a way I can specify the condition as a variable or a function and then use that specify the conditions in the subset function. Is something like the following possible?

x = (A1 == 30 & A2 == 2 & A3 == "this")
filteredrows = subset(df, x)

Thanks in advance.

  • 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-23T09:35:20+00:00Added an answer on May 23, 2026 at 9:35 am

    You can specify the condition as an expression and then pass it to subset using eval:

    d <- data.frame(x=letters[1:10],y=runif(10))
    ss <- expression(x == "a")
    subset(d, eval(ss))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a dataframe like this one: df <- data.frame (id = c(a,
Suppose that you have a data frame with many rows and many columns. The
Suppose, you have a data.frame like this: x <- data.frame(v1=1:20,v2=1:20,v3=1:20,v4=letters[1:20]) How would you select
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose I have an R data frame with columns that specify location (lat/long), height,
Suppose I have a data frame with columns c1, ..., cn, and a function
Suppose I have a function that creates data frames. I'd like to run that
Suppose I have a date.frame like: df <- data.frame(a=1:5, b=sample(1:5, 5, replace=TRUE), c=5:1) df
I have a data.frame, d1, that has 7 columns, the 5th through 7th column
Suppose I have any data stored in bytes. For example: 0110001100010101100101110101101 How can 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.