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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:51:04+00:00 2026-06-04T18:51:04+00:00

Ok, second R question in quick succession. My data: Timestamp St_01 St_02 … 1

  • 0

Ok, second R question in quick succession.

My data:

           Timestamp    St_01  St_02 ...
1 2008-02-08 00:00:00  26.020 25.840 ...
2 2008-02-08 00:10:00  25.985 25.790 ...
3 2008-02-08 00:20:00  25.930 25.765 ...
4 2008-02-08 00:30:00  25.925 25.730 ...
5 2008-02-08 00:40:00  25.975 25.695 ...
...

Basically normally I would use a combination of ddply and summarize to calculate ensembles (e.g. mean for every hour across the whole year).

In the case above, I would create a category, e.g. hour (e.g. strptime(data$Timestamp,"%H") -> data$hour and then use that category in ddply, like ddply(data,"hour", summarize, St_01=mean(St_01), St_02=mean(St_02)...) to average by category across each of the columns.

but here is where it gets sticky. I have more than 40 columns to deal with and I’m not prepared to type them all one by one as parameters to the summarize function. I used to write a loop in shell to generate this code but that’s not how programmers solve problems is it?

So pray tell, does anyone have a better way of achieving the same result but with less keystrokes?

  • 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-06-04T18:51:06+00:00Added an answer on June 4, 2026 at 6:51 pm

    You can use numcolwise() to run a summary over all numeric columns.

    Here is an example using iris:

    ddply(iris, .(Species), numcolwise(mean))
         Species Sepal.Length Sepal.Width Petal.Length Petal.Width
    1     setosa        5.006       3.428        1.462       0.246
    2 versicolor        5.936       2.770        4.260       1.326
    3  virginica        6.588       2.974        5.552       2.026
    

    Similarly, there is catcolwise() to summarise over all categorical columns.

    See ?numcolwise for more help and examples.


    EDIT

    An alternative approach is to use reshape2 (proposed by @gsk3). This has more keystrokes in this example, but gives you enormous flexibility:

    library(reshape2)

    miris <- melt(iris, id.vars="Species")
    x <- ddply(miris, .(Species, variable), summarize, mean=mean(value))
    
    dcast(x, Species~variable, value.var="mean")
         Species Sepal.Length Sepal.Width Petal.Length Petal.Width
    1     setosa        5.006       3.428        1.462       0.246
    2 versicolor        5.936       2.770        4.260       1.326
    3  virginica        6.588       2.974        5.552       2.026
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question, does Kohana (version 3) automatically escape data that is passed into ORM::factory.....
Quick question: I need an event that fires every second, just like the timer1_timer()
(second question today - must be a bad day) I have a dataframe with
Second question of the day but hopefully simple, I just need to change the
This is my second question on Bamboo ( My First One ). My understanding
It's my second question, one after another. That's the problem with assembly (x86 -
So, my second question based off of this application I'm teaching myself Objective C
I hope it's the heat, this is the second question today and it's one
Referring second answer to question: How to convert from ASCII to Hex and vice
Quick question about the TransactionScope object. Found this on the internet: When you access

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.