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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:21:10+00:00 2026-05-20T00:21:10+00:00

I am using R for some statistical analysis of time series. I have tried

  • 0

I am using R for some statistical analysis of time series. I have tried Googling around, but I can’t seem to find any definitive answers. Can any one who knows more please point me in the right direction?

Example:

Let’s say I want to do a linear regression of two time series. The time series contain daily data, but there might be gaps here and there so the time series are not regular. Naturally I only want to compare data points where both time series have data. This is what I do currently to read the csv files into a data frame:

library(zoo)
apples <- read.csv('/Data/apples.csv', as.is=TRUE)
oranges <- read.csv('/Data/oranges.csv', as.is=TRUE)
apples$date <- as.Date(apples$date, "%d/%m/%Y")
oranges$date <- as.Date(oranges$date, "%d/%m/%Y")
zapples <- zoo(apples$close,apples$date)
zoranges <- zoo(oranges$close,oranges$date)
zdata <- merge(zapples, zoranges, all=FALSE)
data <- as.data.frame(zdata)

Is there a slicker way of doing this?

Also, how can I slice the data, e.g., select the entries in data with dates within a certain period?

  • 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-20T00:21:11+00:00Added an answer on May 20, 2026 at 12:21 am

    Try something along these lines. This assumes that the dates are in column 1. The dyn package can be used to transform lm, glm and many similar regression type functions to ones that accept zoo series. Write dyn$lm in place of lm as shown:

    library(dyn) # also loads zoo
    fmt <- "%d/%m/%Y"
    zapples <- read.zoo('apples.csv', header = TRUE, sep = ",", format = fmt)
    zoranges <- read.zoo('oranges.csv', header = TRUE, sep = ",", format = fmt)
    zdata <- merge(zapples, zoranges)
    dyn$lm(..whatever.., zdata)
    

    You don’t need all = FALSE since lm will ignore rows with NAs under the default setting of its na.action argument.

    The window.zoo function can be used to slice data.

    Depending on what you want to do you might also want to look at the xts and quantmod packages.

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

Sidebar

Related Questions

I am using HighCharts for displaying some statistical data but i have a problem
Here's the issue: I am using R to run some statistical analysis. The results
I have been using some Javascript to create a text field once an certain
In order to do some statistical analysis I need to extract values in a
I have calculated some statistical values of an Enviromental Index over a number of
Hello, Specs: VS 2010 C++ professional edition. I have a project with some statistical
For statistical reasons, I want an extensive analysis from a dataset. I already have
like the plots in: http://www.cs.berkeley.edu/~ballard/cs267.sp11/hw1/results/ Using some statistics tool(such as R, matlab) could achieve
I'd like to draw some statistics charts using QT4.7 , here are some examples:
Using some of the methods, I am able to check the orientations to which

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.