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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:49:43+00:00 2026-06-11T17:49:43+00:00

I have a data.frame in which each gene name is repeated and contains values

  • 0

I have a data.frame in which each gene name is repeated and contains values for 2 conditions:

df <- data.frame(gene=c("A","A","B","B","C","C"),
condition=c("control","treatment","control","treatment","control","treatment"),
count=c(10, 2, 5, 8, 5, 1), 
sd=c(1, 0.2, 0.1, 2, 0.8, 0.1))

  gene condition count  sd
1    A   control    10 1.0
2    A treatment     2 0.2
3    B   control     5 0.1
4    B treatment     8 2.0
5    C   control     5 0.8
6    C treatment     1 0.1

I want to calculate if there is an increase or decrease in “count” after treatment and mark them as such and/or subset them. That is (pseudo code):

for each unique(gene) do 
   if df[geneRow1,3]-df[geneRow2,3] > 0 then gene is "up"
       else gene is "down"

This what it should look like in the end (the last columns is optional):

up-regulated
 gene condition count  sd  regulation
 B    control     5    0.1    up
 B    treatment   8    2.0    up

down-regulated
 gene condition count  sd  regulation
 A    control     10   1.0    down
 A    treatment   2    0.2    down
 C    control     5    0.8    down
 C    treatment   1    0.1    down

I have been raking my brain with this, including playing with ddply, and I’ve failed to find a solution – please a hapless biologist.

Cheers.

  • 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-11T17:49:44+00:00Added an answer on June 11, 2026 at 5:49 pm

    The plyr solution would look something like:

    library(plyr)
    reg.fun <- function(x) {
      reg.diff <- x$count[x$condition=='control'] - x$count[x$condition=='treatment']
      x$regulation <- ifelse(reg.diff > 0, 'up', 'down')
    
      x
    }
    
    ddply(df, .(gene), reg.fun)
    
    
      gene condition count  sd regulation
    1    A   control    10 1.0         up
    2    A treatment     2 0.2         up
    3    B   control     5 0.1       down
    4    B treatment     8 2.0       down
    5    C   control     5 0.8         up
    6    C treatment     1 0.1         up
    > 
    

    You could also think about doing this with a different package and/or with data in a different shape:

    df.w <- reshape(df, direction='wide', idvar='gene', timevar='condition')
    
    library(data.table)
    DT <- data.table(df.w, key='gene')
    
    DT[, regulation:=ifelse(count.control-count.treatment > 0, 'up', 'down'), by=gene]
    
       gene count.control sd.control count.treatment sd.treatment regulation
    1:    A            10        1.0               2          0.2         up
    2:    B             5        0.1               8          2.0       down
    3:    C             5        0.8               1          0.1         up
    >     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume that we have a data frame x which contains the columns job
I have a data frame in which each column is a time series of
I have a data frame that contains ID variables, timepoints, and response values. I'm
I have a data.frame (which I melted using the melt function), from which I
I have a data.frame called series_to_plot.df which I created by combining a number of
I have a data frame with two qualitative variables (Q1, Q2) which are both
I have a matrix A which I want to convert into a data.frame of
I have a data frame like below (20,000 rows by 49 cols). Each row
I have a file, called genes.txt , which I'd like to become a data.frame.
I have a data frame which can be generated with: a <- c(rep(w,3), rep(x,3),

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.