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

  • Home
  • SEARCH
  • 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 8330211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:03:10+00:00 2026-06-09T02:03:10+00:00

I have a need to create an object to calculate and store 3 sets

  • 0

I have a need to create an object to calculate and store 3 sets of power prices (on-peak, off-peak, and a day average) for 14 nodes in a grid for each month of the year for the past two years. I thought that an embedded list data structure would be appropriate (correct me if this isn’t optimal).

In any case I’m not a fan of using for loops to create this structure. If there is an elegant way to do this I would be grateful if someone could help steer me in the right direction. I’m trying to practice and improve my coding. Thank you.

hb_lz_names <- c("HB_BUSAVG", "HB_HOUSTON", "HB_HUBAVG", "HB_NORTH", "HB_SOUTH", 
"HB_WEST", "LZ_AEN", "LZ_CPS", "LZ_HOUSTON", "LZ_LCRA", "LZ_NORTH", 
"LZ_RAYBN", "LZ_SOUTH", "LZ_WEST")

power_price <- list()
for (i in 1:2){
  power_price[[i]] <- list()
  for (j in 1:12){
    power_price[[i]][[j]] <- list()
    for (k in 1:NROW(hb_lz_names)) {
      power_price[[i]][[j]][[k]] <- list()
      for (l in 1:3){
        power_price[[i]][[j]][[k]][[l]] <- l
      }
      names(power_price[[i]][[j]][[k]]) <- c("on-peak", "off-peak", "average")
    }
    names(power_price[[i]][[j]]) <- hb_lz_names
  }
  names(power_price[[i]]) <- c("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug",
                             "sep", "oct", "nov", "dec")
}
names(power_price) <- c("2011", "2012")
  • 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-09T02:03:12+00:00Added an answer on June 9, 2026 at 2:03 am

    I think that for a regular (not ragged) data set like this you will be much better off using an array:

    period_names <- c("on-peak", "off-peak", "average")
    hb_lz_names <- c("HB_BUSAVG", "HB_HOUSTON", "HB_HUBAVG", "HB_NORTH", "HB_SOUTH", 
    "HB_WEST", "LZ_AEN", "LZ_CPS", "LZ_HOUSTON", "LZ_LCRA", "LZ_NORTH", 
    "LZ_RAYBN", "LZ_SOUTH", "LZ_WEST")
    yrs <- 2011:2012
    
    power.price <- array(1,dim=c(2,12,length(hb_lz_names),length(period_names)))
    dimnames(power.price) <- list(year=yrs,month=month.abb,node=hb_lz_names,
                                  period=period_names)
    

    (Giving names to the elements in the dimnames list — i.e. naming your dimensions — can be a big help in trying to remember the array structure …)

    You can then easily compute averages (or other summary statistics) across the appropriate margins by using apply, and convert to long format (for ggplot graphics or statistical analysis) using reshape2::melt … in my experience, deeply nested lists are a pain in the butt.

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

Sidebar

Related Questions

I have a need to create a library of Object Oriented PHP code that
Suppose I have an array of nodes (objects). I need to create a duplicate
I have the need to take a string argument and create an object of
I have two objects I need to create a relationship between in Core Data.
I have a need to create a HttpSession (via cookie) whenever a client invokes
I have a need to create a small pop up information box when a
I have a need to create a wrapper for a DLL, loading and unloading
I have the need to create Sharepoint blog comments by code: SPSecurity.RunWithElevatedPrivileges(delegate() { sw.AllowUnsafeUpdates
I have a need to create a utility in Suze Linux. The utility will
I have a need to basically create a matrix of values in my Silverlight

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.