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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:39:54+00:00 2026-06-12T21:39:54+00:00

I have a p structure in R memory and I’m trying to access the

  • 0

I have a p structure in R memory and I’m trying to access the Rate column of the matrix.

When I type p$6597858$Sample in the console, I get …

 p$`6597858`$Sample
        Rate             Available                 X                    Y
[1,]    1.01              1520.93                0.00                  0.0
[2,]    1.02               269.13                0.00                  0.0
[3,]    1.03               153.19                0.00                  0.0
[4,]    1.04               408.80                0.00                  0.0

and so on …

Within my code when I try to

get("p$`6597858`$Sample[,1]") 

I get this returned …

object 'p$`6597858`$Sample[ ,1]' not found

Is this an apostrophe problem?

  • 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-12T21:39:56+00:00Added an answer on June 12, 2026 at 9:39 pm

    Neither the $ nor the [[ operator work within get() (because p[[1]] is not an R object, it’s a component of the object p).

    You could try

    p <- list(`6597858`=list(Sample=data.frame(Rate=1:3,Available=2:4)))
    z <- eval(parse(text="p$`6597858`$Sample[,1]"))
    

    but it’s probably a bad idea. Is there a reason that

    z <- p[["6597858"]][["Sample"]][,"Rate"]
    

    doesn’t do what you want?

    You can do this dynamically by using character variables to index, still without using get: for example

    needed <- 1234
    x <- p[[as.character(needed)]][["Sample"]][,"Rate"]
    

    (edit: suggested by Hadley Wickham in comments) or

    x <- p[[c(as.character(needed),"Sample","Rate")]]
    

    (if the second-lowest-level element is a data frame or list: if it’s a matrix, this alternative won’t work, you would need p[[c(as.character(needed),"Sample")]][,"Rate"] instead)

    This is a situation where figuring out the idiom of the language and working with it (rather than struggling against it) will pay off …

    library(fortunes)
    fortune(106)
    
    If the answer is parse() you should usually rethink the question.
       -- Thomas Lumley
          R-help (February 2005)
    

    In general,

    • extracting elements directly from lists is better (safer, leads to less convoluted code) than using get()
    • using non-standard names for list elements (i.e. those such as pure numbers that need to be protected by backticks) is unwise
    • [[ is more robust than $
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Must I free structure memory after using it? I have sample code: struct aa
I have a question about structure padding and memory alignment optimizations regarding structures in
I have read some vague statement that virtual inheritance doesn't provide the memory structure
I have a structure to represent strings in memory looking like this: typedef struct
I have a structure that contains a pointer to a fixed sized memory. Say,
Suppose I have a structure, and a pointer to a memory location p, how
I have a multithreaded C++ application which holds a complex data structure in memory
I have data structure which stores POD-structs (each instantiation stores a single type only,
gcc (GCC) 4.7.0 c89 Hello, I have the following structure that I am trying
I have a tree structure in memory that I would like to render in

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.