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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:52:02+00:00 2026-05-27T09:52:02+00:00

I don’t think this question has asked yet (most similar questions are about extracting

  • 0

I don’t think this question has asked yet (most similar questions are about extracting data or returning a count). I am new to R, so any help would be appreciated!

I have a dataset of multiple runs of an experiment in one file and the data looks like this, where i have all the time steps for each run in rows
time [info] id (unique per run)

I am attempting to calculate when the system reaches equilibrium, which I am defining as stable values in 3 interdependent parameters. I would like to have the contents of rows compared and if they are within 5% of each other over 20 timesteps, to return the timestep at which the stability begins and the id.

So far, I’m thinking it will be something like the following (or maybe have a while loop)(sorry for the bad formatting):

y=1;
z=0; #variables to control the loop
x=0;
for (ID) {
    if (CC at time=x == 0.05+-CC at time=y ) {

       if(z<=20){ #catalogs the number of periods that match
           y++ 
           z++}

      else [save value in column]

   }

else{ #no match for sustained period so start over again
     x++
     y=x+1
     z=0
   }
}

eta: CC is one of my parameters of interest and ranges between 0 and 1 although the endpoints are unlikely.

Here’s a simple example that might help: this is something like how my data looks:

zz <- textConnection("time CC ID 
1          0.99       1
2          0.80       1
3          0.90       1
4          0.91       1
5          0.92       1
6          0.91       1
1          0.99       2
2          0.90       2
3          0.90       2
4          0.91       2
5          0.92       2
6          0.91       2")
Data <- read.table(zz, header = TRUE)
close(zz)

my question is, how can i run through the lines to find out when the value of CC becomes ‘stable’ (meaning it doesn’t change by more than 0.05 over X (here, 3) time steps) so that it would create the following results:

    ID  timeToEQ
1   1   3
2   2   2

does this help? The only way I can think to do this is with a for-loop and I think there must be an easier way!

  • 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-27T09:52:02+00:00Added an answer on May 27, 2026 at 9:52 am

    Here is my code. I will post the explanation in some time.

    require(plyr)
    ddply(Data, .(ID), summarize, timeToEQ = Position(isTRUE, abs(diff(CC)) < 0.05 ))
    
      ID timeToEQ
    1  1        3
    2  2        2
    

    EDIT. Here is how it works.

    1. ddply breaks Data into subsets based on ID.
    2. diff(CC) computes the difference between CC of successive rows.
    3. abs(diff(CC)) < 0.05) returns TRUE if the difference has stabilized.
    4. Position locates the first instance of an element which satisfies isTRUE.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been asked before, so point me to another question
I don't know if this has been asked before, but what i'd like to
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know if this question is trivial or not. But after a couple
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know what to do with this error. How to add data in SQL
Don't worry, I'm not going to ask that question, yet again... I am wanting
Don't know if this has been answered before. Have custom routes to users. If
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't need to do this right now but thinking about the future... What would

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.