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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:53:56+00:00 2026-05-25T05:53:56+00:00

I have a table with 2 columns and I want to plot values from

  • 0

I have a table with 2 columns and I want to plot values from the second column against the sum of N values in the first column in the 5 rows preceding the current row.

How can I achieve this transformation in R without pre-processing externally?

Example:

File: data.csv

7,2
4,8
3,6
7,10
9,3
0,4
8,9
3,4
5,3
4,6

d = read.csv("data.csv", col.names=c("a","b"))
plot(??some_transform??(d$a), d$b)

some_transform should yield the following column:

7 = 7
7+4 = 11
7+4+3 = 14
7+4+3+7 = 21 # Up to this is optional, can start with row 5
7+4+3+7+9 = 30
4+3+7+9+0 = 23
3+7+9+0+8 = 27
7+9+0+8+3 = 27
9+0+8+3+5 = 25
0+8+3+5+4 = 20

So, the plot input is

7,2
11,8
14,6
21,10
30,3
23,4
27,9
27,4
25,3
20,6
  • 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-25T05:53:57+00:00Added an answer on May 25, 2026 at 5:53 am

    The embed function will assemble a matrix with increasing lags from a vector. Take a look at:

     embed(DF[ , ], 5)
    

    So if this is intended to start working at the 5th row, then you could use these results:

     apply(embed(DF[ , 1], 5), 1,sum)
     plot(apply(embed(DF[ , 1], 5), 1,sum) , DF[-(1:4), 2])
    

    EDIT: With your changed specification, add 4 zeros to the beginning of the embed argument. I am displaying the result of using that approach so it is easier to “visualize” the result of that extension to the embed first argument:

    > embed( c(0,0,0,0, DF[ ,1 ]), 5)
          [,1] [,2] [,3] [,4] [,5]
     [1,]   80    0    0    0    0
     [2,]   80   80    0    0    0
     [3,]   80   80   80    0    0
     [4,]   81   80   80   80    0
     [5,]   82   81   80   80   80
     [6,]   82   82   81   80   80
     [7,]   83   82   82   81   80
     [8,]   83   83   82   82   81
     [9,]   90   83   83   82   82
    [10,]   90   90   83   83   82
    [11,]   90   90   90   83   83
    [12,]   84   90   90   90   83
    [13,]   84   84   90   90   90
    [14,]   85   84   84   90   90
    [15,]   85   85   84   84   90
    

    (Usually with embed (see further above) one gets a shortened array, but our questioner was willing to accept the “lead-in” phenomenon.)

    apply(embed( c(0,0,0,0, DF[ ,1 ]), 5), 1,sum)
     plot( apply(embed( c(0,0,0,0, DF[ ,1 ]), 5), 1,sum), DF[, 2])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with 3 columns and want the first one to be
I have table with 3 columns A B C. I want to select *
I have a table with four columns: PartNumber, ValvePartNumber, ActuatorPartNumber, Price I want to
I have a table with the following columns: EntityId, EntityName, EntityProfile, ................. I want
I have a SQL Server table with 2 columns, Code and CodeDesc. I want
i have table with filmname and actors column in sql server 2005 i want
I have an XML column in a table; I want to promote a certain
I want to have one table header be centered over two table columns side
I want to have a table with columns: id, user_id1, and user_id2. basically this
I have a table with columns A, B and C, and I want to

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.