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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:52:53+00:00 2026-06-05T02:52:53+00:00

I have to select a bunch of data from a data frame depending on

  • 0

I have to select a bunch of data from a data frame depending on certain conditions. The data frame looks roughly like this:

  F1 F2 D1 D2
1 A1 B1  1  0
2 A1 B1  1  1
3 A1 B1  0  0
4 A1 B2  1  0
5 A1 B2  0  0
6 A2 B2  1  0
7 A2 B2  1  1

The Fx are factors, and the Dx are data values. What I have to do is the following:

  1. Find rows with data values that match a specific pattern.
  2. For each row that matches that pattern, find all rows that have the same factors
  3. For each unique factor combination, apply some operation to all rows that have that combination

For example,

factors <- unique(data[D1==1 & D2 == 1, c("F1","F2")])

will give me step 1 and most of 2.

And with

data[data$F1 %in% factors$F1 & data$F2 %in% factors%F2,]

I’m getting closer to the solution, but with the example data above, this will select all rows. But rows 4 and 5 should not be selected, because they are not an exact match. How can I add in some sort of condition that required that the %in% matches happen on the same row?

I feel like this is something that should be a common operation and thus R probably has a clever way for doing this.

Any ideas???? Thanks.

  • 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-05T02:52:54+00:00Added an answer on June 5, 2026 at 2:52 am

    You can use the indexing of the data.table package to select all rows that have to be manipulated.

    data <- data.table(data,key="F1,F2")
    data[unique(data[D1 == 1 & D2 == 1,list(F1,F2)])]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Oracle table with data that looks like this: ID BATCH STATUS
I'm running a query which looks like this SELECT parent.field, child.field FROM parent JOIN
Let's say I have SELECT name FROM table which gives me something like foo
I have a script to extract certain data from a much bigger table, with
I have this SQL query: SELECT DISTINCT tb.SERIAL_NUM, tb.REVISION_NUM, tb.JOB_NUM, tb.JOB_TOTAL, tb.TEST_PROC, tb.BOX_NUM, tb.TEST_BENCH,
I have select values as follows: <select id=SelectBox multiple=multiple> <% foreach (var item in
In Oracle I have: SELECT t2.Regkood, t2.naitatel, t2.naitafaks, t3.lahtiolekuaeg, t1.* FROM table1 t1, table2
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I have a table. In this table have select element. How can I find
I have a table with unique usernames and a bunch of string data 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.