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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:41:53+00:00 2026-05-24T15:41:53+00:00

I am having trouble working with a list of xts objects. I get different

  • 0

I am having trouble working with a list of xts objects. I get different and strange behavior when running lapply on the list elements, and sometimes the program segfaults. I am running R 2.12.2 on Ubuntu 9.10, although I was having similar issues running 2.13.1 on Windows XP.

I am attempting to split a dataframe, which contains quarterly financial data, into multiple time series. I am splitting the dataframe on CIK code, which is an integer. The dataframe is:

> head(CQ[,c("datadate","fqtr","cik","ibq","mkvaltq","prccq","sic")])
    datadate fqtr    cik     ibq    mkvaltq prccq  sic
3 2009-12-31    1  61478   3.400  601.12800  6.21 3661
4 2010-03-31    2  61478 -13.000  709.07000  7.31 3661
5 2010-06-30    3  61478  75.900  718.77000  7.41 3661
6 2010-09-30    4  61478  10.900 1231.52400 12.67 3661
7 2004-03-31    3 319126   0.424    9.73455  1.05 3861
8 2004-06-30    4 319126   0.407   13.90650  1.50 3861
...

The code that I am using to create the list of xts objects is:

CQT<-by(CQ[c("datadate","ibq","cik","mkvaltq","prccq","sic","fqtr")],CQ$cik,function(x)
  {
   xts(x,order.by=x$datadate,frequency=4)
  }
)
CQT<-as.list(CQT)

I am not sure that it is strictly necessary to convert to a list, but I feel comfortable with lists.

This creates the following data structure, which appears correct to me:

> head(CQT)
$`20`
           datadate     ibq     cik  mkvaltq     prccq      sic    fqtr
2004-03-31 "2004-03-31" "1.422" "20" " 53.75880" " 21.8000" "3823" "1" 
2004-06-30 "2004-06-30" "1.389" "20" " 55.04400" " 22.0000" "3823" "2" 
2004-09-30 "2004-09-30" "1.562" "20" " 55.69816" " 22.1200" "3823" "3" 
2004-12-31 "2004-12-31" "2.237" "20" " 67.11840" " 26.5500" "3823" "4" 
2005-03-31 "2005-03-31" "1.643" "20" " 77.28716" " 30.4400" "3823" "1" 
2005-06-30 "2005-06-30" "1.916" "20" " 75.12520" " 29.3000" "3823" "2" 
...

The problem occurs when I try to run lapply on CQT. After experiencing problems multiple times, I have condensed my testing code to:

lapply(CQT,function(x) {
  lag.xts(x[,"prccq"],1)
  }
)

I figure if I can get this working, then I might be on the right track.

This code only segfaults sometimes. For instance, on the most recent iteration that I ran (for the purposes of posting), the code gets through a number of records just fine. For instance:

$`6494`
           prccq  
2004-03-31 NA     
2004-06-30 "0.240"
2004-09-30 "0.150"
2004-12-31 "0.090"
2005-03-31 "0.062"
...

However, it will then throw:

$`6720`

Error in vector(storage.mode(x)) : 
vector: cannot make a vector of mode 'NULL'.

This is not always the error: sometimes I get complaints about characters or something else, and it has never halted on the same record twice. There does not appear to be anything wrong with this particular record:

> CQT$"6720"
           datadate     ibq        cik    mkvaltq    prccq   sic    fqtr
2004-03-31 "2004-03-31" "  10.740" "6720" "559.8638" "16.03" "3949" "1" 
2004-06-30 "2004-06-30" "   6.178" "6720" "558.6060" "15.70" "3949" "2" 
2004-09-30 "2004-09-30" "  13.198" "6720" "667.6474" "14.31" "3949" "3" 
2004-12-31 "2004-12-31" "   8.825" "6720" "743.1205" "15.88" "3949" "4" 
2005-03-31 "2005-03-31" "   2.324" "6720" "643.6650" "13.75" "3949" "1" 
2005-06-30 "2005-06-30" "   1.453" "6720" "594.0200" "12.68" "3949" "2" 
2005-09-30 "2005-09-30" "  16.740" "6720" "534.5802" "11.40" "3949" "3" 
2005-12-31 "2005-12-31" "-232.078" "6720" "474.1590" "10.11" "3949" "4" 
2006-03-31 "2006-03-31" "   3.642" "6720" "589.5614" "12.55" "3949" "1" 
2006-06-30 "2006-06-30" "   2.143" "6720" "514.9567" "10.94" "3949" "2" 
2006-09-30 "2006-09-30" "  21.518" "6720" "552.9757" "11.73" "3949" "3" 
2006-12-31 "2006-12-31" "  10.385" "6720" "651.7707" "13.19" "3949" "4" 
2007-03-31 "2007-03-31" "   4.767" "6720" "597.7659" "12.09" "3949" "1" 

I am kind of at my wit’s end over this. I am not sure if I am coding incorrectly (I was not able to find good examples of working with lists of xts objects), or if there is a problem with my xts package. I have reinstalled xts by removing the package and then reinstalling, using the R-Forge repo, so I should have the most recent version.

Please let me know if there is any additional information I can provide.

  • 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-24T15:41:54+00:00Added an answer on May 24, 2026 at 3:41 pm

    The issue is that lag’s C code is now in the zoo package, with the patch applied to the R-forge sources – not yet to the CRAN version. This was fixed about a week ago.

    Update your version of zoo (from R-forge, version number may be the same still) and you should find that it works.

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

Sidebar

Related Questions

I am having trouble working out how to get a simple fade in fade
Background - I can get HttpListener working fine for HTTP traffic. I'm having trouble
I'm having trouble understanding how to get the following working in interface builder. I've
Using Mongokit with Python. Having some trouble working out get the last n number
Having trouble working out how to do the following - I want to list
I'm having trouble with getting a named scope working using using an attribute of
I am having trouble with a homework question that I've been working at for
I'm working with the Office Interop and having trouble inserting page breaks in Excel.
I'm working on a fairly large site and am having trouble managing z-indexes. Is
I'm having trouble getting the autocomplete box in System.Windows.Controls.Input working as I wish. When

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.