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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:05:00+00:00 2026-06-06T08:05:00+00:00

I have a table in R with the following structure: ID var1 var2 var3

  • 0

I have a table in R with the following structure:

ID var1 var2 var3 .... varN
AA  1    2    1          3
AB  0.2  1    4          1

…

How can I select only those rows where var1<2 and var2<2 and var3<2 and … varN<2 ?

  • 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-06T08:05:02+00:00Added an answer on June 6, 2026 at 8:05 am

    If your dataframe is dat the test for all elements in a row being less than 2 and retruning only those rows would be:

    dat[ apply( apply(dat[-1], 1, "<" ,2) , 2, all ), ]
    

    The logic: the inner apply returns a logical matrix:

    apply(dat[-1], 1, "<" ,2)
         [,1]  [,2]  [,3]
    var1 TRUE  TRUE  TRUE
    var2 TRUE FALSE  TRUE
    var3 TRUE  TRUE FALSE
    varN TRUE FALSE  TRUE
    

    Notice that it is transposed in dimensions, since R matrices are constructed column-major order, so the outer apply needs to work on columns, hence the use of 2 as the INDEX for applying the all function. Testing:

     dat <- read.table(text="ID var1 var2 var3  varN
     BA  1  1  1  1
     AA  1    2    1          3
     AB  0.2  1    4          1", header=TRUE)
    
     dat[ apply( apply(dat[-1], 1, "<" ,2) , 2, all ), ]
    #  ID var1 var2 var3 varN
    #1 BA    1    1    1    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table (table1) structure as the result of a select case
I have mysql table with the following structure. All records are static and only
I have table with following structure and test records: +--------+--------+---------+ | vid | number
I have table with following structure Whenever user click on checkbook and click on
I have table with following structure and records. table t1 +------+-------------+---------------------+ | name |
I have DB2 table having following structure CREATE TABLE DUMMY ( ID CHARACTER(10) NOT
I have a table emp with following structure and data: name dept salary -----
I have a table with the following structure id(int) | col1(int) | col2(int) |
I have the following table structure: ID | fname | lname | street |
I have the following table structure inside a view which gets displayed in the

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.