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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:07:45+00:00 2026-05-14T06:07:45+00:00

I have a timeseries of samples in R: > str(d) ‘data.frame’: 5 obs. of

  • 0

I have a timeseries of samples in R:

> str(d)
 'data.frame': 5 obs. of  3 variables:
 $ date: POSIXct, format: "2010-03-04 20:47:00" "2010-03-04 21:47:00" ...
 $ x   : num  0 10 11 15.2 20
 $ y   : num  0 5 7.5 8.4 12.5
> d
                 date    x    y
1 2010-03-04 20:47:00  0.0  0.0
2 2010-03-04 21:47:00 10.0  5.0
3 2010-03-04 22:47:00 11.0  7.5
4 2010-03-04 23:47:00 15.2  8.4
5 2010-03-05 00:47:00 20.0 12.5

In this example samples for x and y are taken every hour (but the time delta is not fix).
The x and y values are always growing (like a milage counter in a car). I need the deltas,
how much was the growth in between, something like this:

1 2010-03-04 20:47:00  0.0  0.0
2 2010-03-04 21:47:00 10.0  5.0
3 2010-03-04 22:47:00 1.0   2.5
4 2010-03-04 23:47:00 4.2   0.9
5 2010-03-05 00:47:00 4.8   4.1

And I also need the deltas per time (x and y delta, divided by the time – delta per hour)

How would I do this in R?

  • 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-14T06:07:45+00:00Added an answer on May 14, 2026 at 6:07 am

    Just use diff() once switched to a time-aware data structure like zoo:

    > library(zoo)
    > DF <- data.frame(date=Sys.time() + 0:4*3600, x = cumsum(runif(5)*10), 
                                                   y=cumsum(runif(5)*20))
    > DF
                     date       x      y
    1 2010-04-09 15:14:54  9.6282 14.709
    2 2010-04-09 16:14:54 12.4041 28.665
    3 2010-04-09 17:14:54 18.1643 34.244
    4 2010-04-09 18:14:54 27.5785 41.028
    5 2010-04-09 19:14:54 33.2779 57.020
    > zdf <- zoo(DF[,-1], order.by=DF[,1])
    > diff(zdf)
                             x       y
    2010-04-09 16:14:54 2.7759 13.9556
    2010-04-09 17:14:54 5.7602  5.5792
    2010-04-09 18:14:54 9.4142  6.7844
    2010-04-09 19:14:54 5.6995 15.9919
    > 
    

    You can easily pad the first row back, merge, … etc — see the excellent documentation for package zoo for details.

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

Sidebar

Related Questions

I have a data.frame of a time series of data, I would like to
I have an XTS timeseries in R of the following format and am trying
I have timeseries data for many terms an example of which is below: term1
I have timeseries data from three different sensors over the period of a year,
I have a standard financial timeseries of data which has gaps for when the
I have a set of tables in SQL Server 2005 which contain timeseries data.
I have the following data which is a timeseries of data points (see dput()
I have a timeseries class that, over the course of a day will hold
I have a time series: dDate=seq(as.POSIXct(2012/1/1), as.POSIXct(2012/1/10), day) dDate [1] 2012-01-01 PST 2012-01-02 PST
I have data at a number of days since an event. This data is

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.