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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:51:28+00:00 2026-05-25T23:51:28+00:00

Here is a small example to illustrate my data: > df <- data.frame(subgroup=rep(paste(s,1:3, sep=),

  • 0

Here is a small example to illustrate my data:

> df <- data.frame(subgroup=rep(paste("s",1:3, sep=""), times=3),
                   feature=c(rep("a",6), rep("b",3)),
                   var=rep(1:3, each=3),
                   data=c(rnorm(3,1), rnorm(3,2), rnorm(3,0)))
> df
  subgroup feature var        data
1       s1       a   1  1.53152620
2       s2       a   1  1.25476445
3       s3       a   1  1.04221040
4       s1       a   2  1.68913400
5       s2       a   2  1.48290273
6       s3       a   2  1.62871854
7       s1       b   3  0.05278296
8       s2       b   3 -0.66623654
9       s3       b   3 -1.40006454

I want to examine the sum of the “data” column for each combination of feature-var that are present in my dataset. More precisely, I want to obtain TRUE when the sum is bigger than 3, and FALSE otherwise:

> result
  feature snp   res
1       a   1  TRUE
2       a   2  TRUE
3       b   3 FALSE

I tried using “aggregate” or “by”, but can’t make them fit my need. Any idea? 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-25T23:51:29+00:00Added an answer on May 25, 2026 at 11:51 pm

    One approach is to use plyr‘s function ddply to group on feature and var. You can use the summarize function to create a new data.frame with a column that corresponds to the rule you developed.

    library(plyr)
    ddply(df, c("feature", "var"), summarize, res = ifelse(sum(data) > 3,TRUE, FALSE))
    

    Results in:

      feature var   res
    1       a   1  TRUE
    2       a   2  TRUE
    3       b   3 FALSE
    

    Another alternative is to use data.table which is supposed to provide some performance benefits:

    library(data.table)
    dt <- data.table(df)
    
    dt[, ifelse(sum(data) > 3, TRUE, FALSE), by = c("feature", "var")]
    
         feature var    V1
    [1,]       a   1  TRUE
    [2,]       a   2  TRUE
    [3,]       b   3 FALSE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a small Example of what I would like to achieve: Maven Artifact
Here is a small example of my experience with that issue: I started to
Here's a small example (download, rename to .php and execute it in your shell):
i try to create small example to test GPS here package org.example.location; import com.google.android.maps.MapActivity;
Here is a small example with the masked input plugin : //apply the mask
Here I got a small example which causes the compliler to deliver a error
Here I got small example how to run Yaws embedded, but how I need
I have put together a small example here just to replicate the problem. I
I'm having a small issue here: <div id=navbar> <ul id=navtabs class=floatcontainer> <li <?php if
I am stuck with a small problem here.. What i am trying to do

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.