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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:10:18+00:00 2026-05-28T15:10:18+00:00

I am trying to make a function that will determine if value in a

  • 0

I am trying to make a function that will determine if value in a column of a data frame is a new high. So for example if I had the following data:

x <- rnorm(10,100,sd=5)
x <- data.frame(x)

How can I return, TRUE or FALSE in a new column that only takes into account all the previous values. The resulting table would look something like:

           x   new.max
1  102.42810   NA
2  109.22762   TRUE
3  101.97970   FALSE
4  101.49303   FALSE
5   93.30595   FALSE
6   96.77199   FALSE
7  110.96441   TRUE
8   96.27485   FALSE
9  101.77163   FALSE
10 100.78992   FALSE

If I try

x$new.max <- ifelse ( x$x == max(x$x) , TRUE, FALSE )

The resulting table is below, as it calculates the maximum value of the entire column instead of a subset of all the previous values.

           x new.max
1  102.42810   FALSE
2  109.22762   FALSE
3  101.97970   FALSE
4  101.49303   FALSE
5   93.30595   FALSE
6   96.77199   FALSE
7  110.96441   TRUE
8   96.27485   FALSE
9  101.77163   FALSE
10 100.78992   FALSE
  • 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-28T15:10:20+00:00Added an answer on May 28, 2026 at 3:10 pm

    There is a built-in function that computes the running maximum, called cummax().

    diff(cummax(x)) will be non-zero at positions where a new maximum is achieved (there’s no entry for the first element of x, which is always a new maximum).

    Putting the pieces together:

    new.max <- c(TRUE, diff(cummax(x)) > 0)
    

    I’ve set the first element to TRUE, but it could just as well be NA.

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

Sidebar

Related Questions

i am trying to write a function that will make DataRow[column] return nullable typed
Im trying to make a function that will return an element of type point:
I'm trying to make a function that will take short hand hex color to
I'm trying to make a Javascript function that will take a mathematical expression and
I'm trying to make a notification area that will show alerts. return this.each(function() {
I am trying to make a function in C that will print a string
I am trying to make a function in PHP that will allow me to
Hi I'm trying to make a function that will add a striped effect to
I'm trying to make a function that takes two data types, each of which
I'm trying to make a spellcheck function in my application that will show a

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.