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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:00:40+00:00 2026-05-28T18:00:40+00:00

If I had a data frame of 20 values: x <- data.frame(runif(20,10,90)) And I

  • 0

If I had a data frame of 20 values:

x <- data.frame(runif(20,10,90))

And I wanted to create another column of the cumulative maximums of no more than the 5 previous values how would I do that? Basically it would be a sliding window of the 5 previous values. Below is the data of how a normal cummax would be done and a sliding cummax, I indicated where the change is apparent.

   runif           normal cummax    sliding cummax
1  42.84205          42.84205         42.84205
2  17.17040          42.84205         42.84205
3  50.08326          50.08326         50.08326
4  21.47712          50.08326         50.08326
5  59.30754          59.30754         59.30754
6  16.49770          59.30754         59.30754
7  89.52601          89.52601         89.52601
8  49.91727          89.52601         89.52601
9  69.84386          89.52601         89.52601
10 13.92894          89.52601         89.52601
11 56.39335          89.52601         89.52601
**12 28.30264          89.52601         69.84386**
13 60.09056          89.52601         69.84386
14 17.79935          89.52601         60.09056
15 63.53476          89.52601         63.53476
16 62.98458          89.52601         63.53476
17 67.21095          89.52601         67.21095
18 16.01599          89.52601         67.21095
19 39.99181          89.52601         67.21095
20 40.96641          89.52601         67.21095
  • 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-28T18:00:42+00:00Added an answer on May 28, 2026 at 6:00 pm
    > library(TTR)
    > set.seed <- 1234
    > x <- data.frame(runif(20,10,90))
    > x[[2]] <- runMax(x, n=5)
    > x
       runif.20..10..90.       V2
    1           79.18671       NA
    2           13.34858       NA
    3           35.37457       NA
    4           11.10000       NA
    5           29.12206 79.18671
    6           66.51957 66.51957
    7           34.64758 66.51957
    8           50.68381 66.51957
    9           14.13173 66.51957
    10          55.16559 66.51957
    11          19.71841 55.16559
    12          81.42691 81.42691
    13          11.17018 81.42691
    14          72.64969 81.42691
    15          17.19691 81.42691
    16          51.53520 81.42691
    17          40.74134 72.64969
    18          15.60420 72.64969
    19          35.65155 51.53520
    20          63.47963 63.47963
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a vector of datetime values, I needed to create a data.frame containing datetimes
Note: I had another similar question about how to GZIP data using Ruby's zlib
assuming i had RGBA (32 bits) output from frame-grabber, with alpha channel unused (values
I have a data frame with two columns, and want to create a third
I have a data frame with a date column and some other value columns.
I have a data frame that contains ID variables, timepoints, and response values. I'm
Say I had the dataframe df <- data.frame('A' = c('a','a','a','a','b','b','b','b','b'), 'B' = c('y','y','z','z','y','y','y','z','z'), 'value'=c(1
I have a data frame with two columns. The first column defines subsets of
I have a live database that had some data deleted from it and I
Suppose I'm making a JDBC call and I had fetched data from a database

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.