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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:55:13+00:00 2026-05-25T05:55:13+00:00

I am trying to calculate a simple ratio using data.table. Different files have different

  • 0

I am trying to calculate a simple ratio using data.table. Different files have different tmax values, so that is why I need ifelse. When I debug this, the dt looks good. The tmaxValue is a single value (the first “t=60” encountered in this case), but t0Value is all of the “t=0” values in dt.

summaryDT <- calculate_Ratio(reviewDT[,list(Result, Time), by=key(reviewDT)])

calculate_Ratio <- function(dt){
tmaxValue <- ifelse(grepl("hhep", inFile, ignore.case = TRUE), 
    dt[which(dt[,Time] == "t=240min"),Result],
    ifelse(grepl("hlm",inFile, ignore.case = TRUE), 
        dt[which(dt[,Time] == "t=60"),Result],
        dt[which(dt[,Time] == "t=30"),Result]))
t0Value <- dt[which(dt[,Time] == "t=0"),Result]
return(dt[,Ratio:=tmaxValue/t0Value])
}

What I am getting out is theResult for tmaxValue divided by all of the Result‘s for all of the t0Value‘s, but what I want is a single ratio for each unique by.

Thanks for the help.

  • 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-25T05:55:13+00:00Added an answer on May 25, 2026 at 5:55 am

    You didn’t provide a reproducible example, but typically using ifelse is the wrong thing to do.

    Try using if(...) ... else ... instead.

    ifelse(test, yes, no) acts very weird: It produces a result with the attributes and length from test and the values from yes or no.
    …so in your case you should get something without attributes and of length one – and that’s probably not what you wanted, right?

    [UPDATE] …Hmm or maybe it is since you say that tmaxValue is a single value…
    Then the problem isn’t in calculating tmaxValue? Note that ifelse is still the wrong tool for the job…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a simple COUNT from a table that takes a couple of
I am trying to write a class that will calculate checksums using multiple processes,
I'm trying to write a simple function in C that would calculate the difference
I'm trying to write a simple game/utility to calculate poker odds. I know there's
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am trying to calculate a determinant using the boost c++ libraries. I found
I'm trying to calculate TimeSpans between dates. I have no problem with this if
I'm trying to calculate the sunset / rise times using python based on the
I am trying to write a simple sieve function to calculate prime numbers in
Im trying to do a simple game where I continually need input from players.

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.