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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:21:30+00:00 2026-05-25T10:21:30+00:00

I have a zoo object called pp with daily data and 77 columns that

  • 0

I have a zoo object called pp with daily data and 77 columns that looks like this:

            X02R X03N X04K X04N X04R X06I X06N X08J X08P X09O X11O X12L X14N X15G X16K  (...)
1961-01-01  8.3  5.2  3.2  0.0  8.7  5.2 15.0  7.2 11.5 13.0  0.0  4.9  0.0  2.9  6.0   
1961-01-02  1.1  3.2 10.0  0.0  0.0  3.5  0.0  8.7  0.4  1.2  0.0  0.4  0.0  3.2  0.2    
1961-01-03 12.0  4.2 50.5  0.0  9.0 38.5 15.0 31.7  1.7  8.7  9.0 69.2  4.2 22.2  9.2 
(...)  

I want to use apply.monthly to each of the columns, so in the end I will still have 77 columns but with monthly data instead of daily data. I tried
apply.monthly(pp, FUN=sum) but the result is a zoo object with just one column (I think is adding all the columns).

I also tried a loop:

for (i in 1:77)
{
mensal<-apply.monthly(pp[,i], FUN=sum)
}
but it also results in just one column (the 77th column). I might be able to make the loop work with some trial and error but it takes ages to compute ( I have 17897 rows and 77 columns) and I guess there is a simpler way of doing this without using loops… So if you know how, please help. Thanks!

  • 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-25T10:21:31+00:00Added an answer on May 25, 2026 at 10:21 am

    In order for apply.monthly to return an object with more than one column, you have to use a function that operates by column (or apply a function that doesn’t).

    library(quantmod)
    getSymbols("SPY")
    zSPY <- as.zoo(SPY)
    # sum doesn't operate by column; it sums everything to one value
    sum(zSPY)
    spy.sum <- apply.monthly(zSPY, sum)
    # colSums operates by column
    spy.colSums <- apply.monthly(zSPY, colSums)
    # use apply to operate by column
    spy.apply.sum <- apply.monthly(zSPY, apply, 2, sum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a zoo with daily data that looks like this: > head(almorol) 1973-10-02
I have some data that looks a bit like this: require(zoo) X <- rbind(c(date='20111001',
I have a large data frame (named z ) that looks like this: RPos
I have a zoo object oi.zoo with weekly data. I would like to sooth
I have a jQuery ajax call that looks like this: $.ajax({ type : 'GET',
I have a time series(a csv file) data that looks like below. Each observation
I have a df/zoo/xts/whatever that is split by day of week. I'd like to
I have commands like this: \bold{Foo Bar} \bold{Foo Bars} \bold{Foos Bar} .... \bold{Zoo Cars}
I have some imported csv data that I have turned into an xts object.
This should be exceptionally simple. I have a zoo object with 500 times series

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.