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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:58:14+00:00 2026-05-27T21:58:14+00:00

I created a list containing two data lists (character array region and a list

  • 0

I created a list containing two data lists (character array region and a list results) of the same length. (I tried to manage the data in data.frame, but it seems to be complicated to add data to a data.frame).

study = list(
    region  = character(),
    results = list()
)

study$region[1] = "Hamburg"
study$results[[1]]  = data.frame(month=c(1:5), maxTemp=c(-12, -1, 3, 10, 23))


study$region[2]    = "Bremen"
study$results[[2]]  = data.frame(month=c(1:5), maxTemp=c(-9, -1, 6, 10, 21))

str(study)

print("Maximum temperature of all study regions:")
max(study$results[[1:2]]$maxTemp)

I want to find out the maximum temperature of all timepoint of all regions. I can address each region after another by using e.g. max(study$results[[1]]$maxTemp, but when I try to address all regions max(study$results[[1:2]]$maxTemp I receive an error:

Error in study$results[[1:2]]$maxTemp :

$ operator is invalid for atomic vectors

Where is my mistake? How can I address fields of a several data.frames that are saved in a list of a list? And what are atomic vectors?

  • 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-27T21:58:15+00:00Added an answer on May 27, 2026 at 9:58 pm

    [[ can only return a single element. I thought [[ would have thrown an error because of that, not the error you are seeing, but reading ?"[" tells what R does with a call such as yours and explains the behaviour (from ?"["):

    Recursive (list-like) objects:
    ….

     ‘[[’ can be applied recursively to lists, so that if the single
     index ‘i’ is a vector of length ‘p’, ‘alist[[i]]’ is equivalent to
     ‘alist[[i1]]...[[ip]]’ providing all but the final indexing
     results in a list.
    

    The reason for your error is this:

    > study$results[[c(1,2)]]
    [1] -12  -1   3  10  23
    

    which indicates that R really did this

    > study$results[[1]][[2]]
    [1] -12  -1   3  10  23
    

    i.e. return the second component (column) of the first data frame, which is an atomic vector because R drops the empty dimension. $ can not be used on atomic vectors hence the error.

    If you want to iterate over the list that is study$results, lapply() or sapply() are your friends:

    > lapply(study$results, function(y) max(y[, "maxTemp"], na.rm = TRUE))
    [[1]]
    [1] 23
    
    [[2]]
    [1] 21
    
    > sapply(study$results, function(y) max(y[, "maxTemp"], na.rm = TRUE))
    [1] 23 21
    

    If you popped names on the components in $results you’d get them in the output too:

    > names(study$results) <- study$region
    > lapply(study$results, function(y) max(y[, "maxTemp"], na.rm = TRUE))
    $Hamburg
    [1] 23
    
    $Bremen
    [1] 21
    
    > sapply(study$results, function(y) max(y[, "maxTemp"], na.rm = TRUE))
    Hamburg  Bremen 
         23      21
    

    which is easier to use and then you don’t need the $region component if you wish.

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

Sidebar

Related Questions

I created a list of lists: >>> xs = [[1] * 4] * 3
I have an array containing data (ID numbers and data associated with them). The
I've created a list using the SharePoint (MOSS 2007) Issue Tracking List. A Comments
I have created a list view that displays the names and dates of items
I have a gridview and in that gridview i created a list of imagebuttons
I created a Linked List, with insert, search and remove functions. I also created
I created drop down list using java. But i am not aware of creating
I created an Archive list ( also this is my archive.php codes ) on
I created a property list with the name propertys.plist. Then I wrote this: NSString
I've created a custom list, and made some changes to the way the CQWP

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.