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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:06:27+00:00 2026-06-15T02:06:27+00:00

Imagine I have a table such as: ScaleDown ScaleUp 1 0 0 2 1

  • 0

Imagine I have a table such as:

        ScaleDown ScaleUp
1           0        0
2           1        0
3           0        0
4           0        1
5           0        0

And what I want to do is perform a scale up or down function on a column so that values will be altered to reflect a positive entry that just happened(scale down) or positive entry coming up(scale up).
So the table should end up looking something like this:

        ScaleDown ScaleUp
1           0        0
2           1       0.33
3          0.66     0.66
4          0.33      1
5           0        0

Any help much appreciated.

  • 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-15T02:06:29+00:00Added an answer on June 15, 2026 at 2:06 am
    # Sample Data
    df <- data.frame(scaleDown=c(0,1,0,0,0,0,1,0,0,0,1), scaleUp=c(0,1,0,0,0,0,0,1,0,1,0))
    
    # Function call with mapply
    mapply(adjust, df, c(F, T), MoreArgs=list(rate=3, rounding=2))
    
    #           scaleDown scaleUp
    #      [1,]      0.00    0.67
    #      [2,]      1.00    1.00
    #      [3,]      0.67    0.00
    #      [4,]      0.34    0.00
    #      [5,]      0.00    0.00
    #      [6,]      0.00    0.34
    #      [7,]      1.00    0.67
    #      [8,]      0.67    1.00
    #      [9,]      0.34    0.50    <{~~ 
    #     [10,]      0.00    1.00
    #     [11,]      1.00    0.00
    

    function:

    adjust <- function(vec, reverse=FALSE, rate=3, rounding=3) {
    
      if (reverse)
        vec <- rev(vec)
    
      # add a dummy "1" to end of vec for calculating ends. Will be removed
      vec <- c(vec, 1)
    
    
      len <- length(vec)
      indx <- which(vec[-len] != 0)
      ends <- c(indx[-1L], (length(vec) + rate))
    
      ranges <- sapply(ends-indx, min, rate)
      subtr <- round(vec[indx]  /  ranges, rounding)
    
      for(i in 1:length(subtr)) {
        for (j in (ranges[i]-1):1) {
          vec[indx[i] + ranges[i]-j] <- vec[indx[i] + ranges[i]-j-1] - subtr[i]
        }
      }
    
      # remove dummy element
      vec <- vec[seq(len-1)]
    
      if (reverse)
        return(rev(vec))
      return(vec)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a table called item that has a column called price. In
Imagine I have this table: Column A | Column B | Column C ------------------------------
Let's imagine that I have to make a table with the following structure with
I have a table that has a view_count column. I would like to increment
So imagine that you have a table of Products (ID int, Name nvarchar(200)) ,
Imagine, that u have 10 Imagelinks (Example of such a Link: CLICK What I
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'
Imagine I have a table which stores a series of sparse vectors. A sparse
Imagine you have a normal table view where each row is an item on
Imagine I have these columns in a table: id int NOT NULL IDENTITY PRIMARY

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.