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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:30:22+00:00 2026-06-18T15:30:22+00:00

I have some data that looks like this: List_name Condition1 Condition2 Situation1 Situation2 List1

  • 0

I have some data that looks like this:

 List_name     Condition1   Condition2  Situation1   Situation2
  List1          0.01         0.12         66           123
  List2          0.23         0.22         45           -34
  List3          0.32         0.23         13           -12
  List4          0.03         0.56         -3            45
  List5          0.56         0.05         12           100
  List6          0.90         0.09         22            32

I would like to filter each column “Condition” of the data.frame according to a cut off 0.5.
After the filter, the subset will occur and will carry the corresponding value of columns “Situation”. Filter and subset will work pairwise: “Condition1” with “Situation1”, “Condition2” with “Situation2” and so on.

Just the desired output:

 List_name     Condition1     Situation1  List_name  Condition2  Situation2
  List1          0.01             66       List1        0.12        123
  List2          0.23             45       List2        0.22        -34
  List3          0.32             13       List3        0.23        -12
  List4          0.03             -3       List5        0.05        100
                                           List6        0.09         32

I’m pretty sure that there’s probably another similar situation posted before but I searched and I didn’t find it.

  • 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-18T15:30:23+00:00Added an answer on June 18, 2026 at 3:30 pm

    You can use the notion that boolean checks are vectorized:

    x <- c(0.1, 0.3, 0.5, 0.2)
    x < 0.5
    # [1]  TRUE  TRUE FALSE  TRUE
    

    And some grep results:

    grep('Condition', names(DF1))
    

    To do this subsetting you can use apply to generate your boolean vector:

    keepers <- apply(DF1[, grep('Condition', names(DF1))], 1, function(x) any(x < 0.5))
    

    And subset:

    DF1[keepers,]
    

    Notice that this doesn’t necessarily return the data structure you showed in your question. But you can alter the anonymous function accordingly using all or a different threshold value.


    In lieu of the edits, I would approach this differently. I would use melt from the reshape2 package:

    library(reshape2)
    dat.c <- melt(DF1, 
                  id.var='List_name', 
                  measure.var=grep('Condition', names(DF1), value=TRUE),
                  variable.name='condition',
                  value.name='cond.val')
    dat.c$idx <- gsub('Condition', '', dat.c$condition)
    dat.s <- melt(DF1, 
                  id.var='List_name', 
                  measure.var=grep('Situation', names(DF1), value=TRUE),
                  variable.name='situation',
                  value.name='situ.val')
    dat.s$idx <- gsub('Situation', '', dat.s$situation)
    dat <- merge(dat.c, dat.s)
    
    out <- dat[dat$cond.val < 0.5,]
    
       List_name idx  condition cond.val  situation situ.val
    1      List1   1 Condition1     0.01 Situation1       66
    2      List1   2 Condition2     0.12 Situation2      123
    3      List2   1 Condition1     0.23 Situation1       45
    4      List2   2 Condition2     0.22 Situation2      -34
    5      List3   1 Condition1     0.32 Situation1       13
    6      List3   2 Condition2     0.23 Situation2      -12
    7      List4   1 Condition1     0.03 Situation1       -3
    10     List5   2 Condition2     0.05 Situation2      100
    12     List6   2 Condition2     0.09 Situation2       32
    

    You can then use dcast to put the data back in the initial format if you want, but I find data in this “long” form much easier to work with. This form is also pleasant since it avoids the need for NA values where you have rows where one condition is met and others are not.

    out.c <- dcast(out, List_name ~ condition, value.var='cond.val')
    out.s <- dcast(out, List_name ~ situation, value.var='situ.val')
    merge(out.c, out.s)
    
      List_name Condition1 Condition2 Situation1 Situation2
    1     List1       0.01       0.12         66        123
    2     List2       0.23       0.22         45        -34
    3     List3       0.32       0.23         13        -12
    4     List4       0.03         NA         -3         NA
    5     List5         NA       0.05         NA        100
    6     List6         NA       0.09         NA         32
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that looks something like this... +----------+----------+----------+ | Column 1 |
I have some data in an XML element that looks like this: <?xml version=1.0
I have some JSON data that looks like this: { data: [{ name:John Smith,
I have some data in MongoDB that looks like this: { name: Steve, location:
I have some data that looks like this: [ { _id : ObjectId(4e2f2af16f1e7e4c2000000a), advertisers
I have some data in a table that looks roughly like the following: table
I have data in my database that looks like this: Date (DateTime) Type (varchar)
I have a model that looks like this: class Pdf extends \lithium\data\Model { protected
I have some data that looks like YAML, but aint. Here is an example;
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>

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.