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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:27:43+00:00 2026-05-23T13:27:43+00:00

I have two data.frame s in R , each indexed by date. One is

  • 0

I have two data.frames in R, each indexed by date. One is coarser than the other and I would like to compare the data only along the coarser timescale.

To be more concrete let’s say one data.frame has time points DF1[a,b,c,...,x,y,z] and the other only has DF2[f,p,t], where p=="July 19, 1917". I wish to compare DF1[f,p,t] to DF2[f,p,t].

This isn’t syntactic but I want to do for each $i { DF_combined <- df1[$i] . df2[$i] if exists(df1[$i]); }. In other words, make a new data.frame that only contains every shared observation day.

I hope the question is clear. I’ve been looking at other SO answers for a couple of hours and haven’t found one that covers what I’m trying to do yet. Thanks in advance.

  • 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-23T13:27:43+00:00Added an answer on May 23, 2026 at 1:27 pm

    Here’s the solution to my problem, from start to finish.

    Problem: Given records from my broker (not evenly spaced in time), put the time series of my net worth next to a time series of the S&P, for comparison in R.

    Answer:

    #get S&P data
    require(quantmod)
    getSymbols("^GSPC", from="2004-01-01", src="yahoo")
    head(GSPC)
    
                  GSPC.Open GSPC.High GSPC.Low GSPC.Close GSPC.Volume GSPC.Adjusted
    2004-01-02   1111.92   1118.85  1105.08    1108.48  1153200000       1108.48
    2004-01-05   1108.48   1122.22  1108.48    1122.22  1578200000       1122.22
    2004-01-06   1122.22   1124.46  1118.44    1123.67  1494500000       1123.67
    

    Notice that there is no header over the dates. That’s because time-series data types embed the time-value as an ordering index. (class(GSPC) = [1] "xts" "zoo" where zoo is a data type totally ordered by an index, and xts is a time series data-type that tolerates more than the restrictive native ts data type tolerates.)

    #coerce the .csv from my broker into a time-series data type as well
    MyNetWorth <- read.csv("/home/joey/Desktop/Historical_NAV.csv")
    require(xts)
    MyNetWorth <- as.xts( MyNetWorth,
                                       order.by= as.Date(MyNetWorth$TradeDate, format="%m/%d/%Y") )
    

    In the date format there is a big difference between %Y (’87) and %y (1987), as well as between %m – months and %M – minutes. My broker wrote 10/23/2009.

    So did I do it right?

    > class(MyNetWorth)
    [1] "xts" "zoo"
    

    Yessss.

    Finally, @Joshua Ulrich’s advice does the kind of merge I want:

    comparison <- merge(GSPC$GSPC.Adjusted, MyNetWorth$NetAssets, join="right")
    

    The right join compares the dates only at the coarser scale (my data is always coarser than Yahoo’s).

    Last of all, to plot the results:

    plot( as.zoo(comparison) , screens=c(1,1), col=c("red", "#333333")  )
    

    Many thanks to all the people who wrote all this open source software — and especially to those who wrote vignettes!

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

Sidebar

Related Questions

I have two data frames. The one consists of three variables, namely date, strike
I have two data.frames, one with only characters and the other one with characters
I have two processes one will query other for data.There will be huge amount
I am trying to merge several data.frames into one data.frame . Since I have
I am using R and I have two data frames: carrots and cucumbers. Each
I have two data.frames in R, one of which has two columns and of
I have two data frames DF1, DF2 each with 2 vectors DF1$A DF1$B, DF2$C,
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two applications written in Java that communicate with each other using XML
I have two small data frames, this_tx and last_tx . They are, in every

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.