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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:07:20+00:00 2026-06-18T07:07:20+00:00

I am working on map data structure in which i need to store key

  • 0

I am working on map data structure in which i need to store key value pair.

 map[key1]<-value1
 map[key2]<-value2
 map[key3]<-value3
 map[key4]<-value4

I need to get value based on key. How can i implement this in R?

  • 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-18T07:07:21+00:00Added an answer on June 18, 2026 at 7:07 am

    Use a list, because a simple vector constructed with c can’t handle anything more than scalar values:

    > map = c(key1 = c(1,2,3), key2 = 2, key3 = 3)
    > map[["key1"]]
    Error in map[["key1"]] : subscript out of bounds
    

    why does this fail? because map is now:

    > map
    key11 key12 key13  key2  key3 
        1     2     3     2     3 
    

    use a list instead:

    > map = list(key1 = c(1,2,3), key2 = 2, key3 = 3)
    > map[["key1"]]
    [1] 1 2 3
    

    also dynamically extensible:

    > map[["key99"]]="Hello You!"
    > map
    $key1
    [1] 1 2 3
    
    $key2
    [1] 2
    
    $key3
    [1] 3
    
    $key99
    [1] "Hello You!"
    

    Start with an empty map=list() if you are building one up.

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

Sidebar

Related Questions

I need to store data in memory where I map one or more key
I'm currently working on a site which displays map data in Google Maps, but
I am working on a GPS data logger and Map viewer application using Microsoft
I am working with google map. According to requirements i need to set different
I'm working on a game which has tank battles on a tiled map. If
I'm working with map data, and the Latitude/Longitude extends to 8 decimal places. For
I've a data structure as follows typedef vector<double> v_t; typedef set<int> s_t; typedef map<s_t,
Actually I need a data structure that helps me in reducing time for look-ups
I'm working with an application and data structure built upon ASP/ADO.NET and I'm converting
i working on map view. i want to put overlay item on the map

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.