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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:04:40+00:00 2026-06-14T10:04:40+00:00

I have a large matrix consisting of 116 columns and 4700 rows. For each

  • 0

I have a large matrix consisting of 116 columns and 4700 rows.

For each row I would like to compute a standardized difference of the following form:

(((a2-a1)/a1)*100)+100, where a1 is the previous value and a2 is the next value.

In R I’m using the following code:

for i in (1:116)

a[i]=(((a[i]-a[i-1])/a[i-1])*100)+100

However I get the following error:

Error in Ops.data.frame(a[i], a[i - 1]) : 
- only defined for equally-sized data frames

I’m guessing that the problem is that it does not take into account the very first value, where there does not exist a first value-1 to substract.

How can I solve this problem?

Here’s a subset of the data: https://dl.dropbox.com/u/22681355/su.csv

Remember that I would like to calculate for each column individually!

  • 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-14T10:04:43+00:00Added an answer on June 14, 2026 at 10:04 am

    Your question could use a reproducible example to make it clearer. For example, you say you have a matrix but then show an error that is related to data frames. Without knowing what your data looks like we can not know if answers are correct.

    But anyway, I think you can do this without loops as follows.

    # Example data:
    foo <- data.frame(A = 1:10, B = rnorm(10))
    
    # Compute standardized differences:
    (foo[-1,] - foo[-nrow(foo),]) / foo[-nrow(foo),] * 100 + 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large matrix from which I would like to gather a collection
I have a large matrix that I would like to center: X <- matrix(sample(1:10,
I have a large matrix from which I would like to randomly extract a
I have a large matrix that I would like to convert to sparse CSR
I have a large matrix mdat (1000 rows and 16 columns) contains first column
I have a matrix of W of large row and column dimension. Each of
I have large images displayed in a grouped tableview. I would like the images
I have a large matrix M implemented as vector<vector<double> with m rows, i.e. the
I have a very large matrix (216 rows, 31286 cols) of doubles. For reasons
I have a large scipy.sparse.csc_matrix and would like to normalize it. That is subtract

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.