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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:44:43+00:00 2026-06-14T22:44:43+00:00

I have a data frame with 4 columns… Date, Hour, Loc, Value. What I’d

  • 0

I have a data frame with 4 columns… Date, Hour, Loc, Value.

What I’d like to do with the data is come up with summary statistic for each unique Date/hour/loc. This seems to be easy since I can do

x <- subset(my.df[,4], 
            my.df[,2]==(some parameter) & my.df[,3]==(another parameter)
           ) 

and then get whatever summary statistics I want from x. However the tricky part is that I also want to get summary statistics from each of the differences of the aforementioned values. So for instance I want to take the difference of value when loc=1 from value when loc=2 with hour=1 but there may or may not be missing days within either of the locs. One idea I had which probably will work is to reshape my.df to be wider twice. Firstly make it wide with timevar=loc and then reshape that with timevar=hour so that I’ll have wide.df with columns Date, value.1.1, value.1.2 etc where the first integer is the loc and the second integer is the hour and each row is a unique date.

Is there a more straight forward to do this that won’t involve 20 minutes of reshaping (the initial df is about 9493401 rows with 4 variables and then I stretch it out to 720 rows with 14857 columns?
@Brandon: Here’s the str output. I haven’t tried your suggestions yet though.

        'data.frame':   9493401 obs. of  4 variables:
    $ Loc  : int  1 1 1 1 1 1 1 1 1 1 ...
    $ Date: POSIXct, format: "2010-10-29" "2010-10-29" ...
    $ Hour     : int  1 2 3 4 5 6 7 8 9 10 ...
    $ Value   : num  7.63 4.07 4.9 1.61 0.34 -5.23 2.11 2.39 7.2 4.41 ...
  • 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-14T22:44:44+00:00Added an answer on June 14, 2026 at 10:44 pm

    There’s dcast from reshape2 which seems to be pretty snappy in this regard:

    library(reshape2)
    dat <- data.frame(date=sample(1:100,9493401,replace=TRUE),
                      hour=rep(1:24,1000000)[1:9493401],
                      loc=rep(letters[1:9],1054823)[1:9493401],
                      value=rnorm(9493401))     
    
    dcast(dat,date + hour ~ loc) 
    

    You can also do things like counts of loc/hour

    dcast(dat, date + hour ~ loc*hour)
    

    You’ll need to provide more information if you want an answer that’s specific to your case.

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

Sidebar

Related Questions

I have a data.frame with 2 columns: Node A, Node B. Each entry in
I have a data frame of daily data: df with four columns: Date, A,
Imagine I have a data frame with 2 columns Id Value 12 13 32
I have a data frame composed of numeric and non-numeric columns. I would like
I have a data frame with two columns: an ID and some numeric value
I have a data.frame with 2 columns dates=dates of observations for each station and
I have a data frame like this (specifically the data.frame contains 50 columns): G1
I have a data frame with three columns and I'd like to make a
I have a data frame of two columns: key and value and I would
I have a data frame with two columns. First column contains categories such as

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.