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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:43:49+00:00 2026-05-26T15:43:49+00:00

This actually corresponds to my other question but things get more complicated. I have

  • 0

This actually corresponds to my other question but things get more complicated. I have data.frame and vector:

df <- data.frame(key=c(0,3:6), value=c(0,52,26,12,1))
x <- c(3,4,3,3,5,5,6,6,6,6)

and need to obtain values from df based on x as keys:

[1] 52 26 52 52 12 12 1 1 1 1

Solution from previous answer can only give result with NO duplicates:

df[df$key %in% x,"value"]
[1] 52 26 12  1

Is there a way to solve this?

Also, I see hash() can do things like:

h <- hash( keys=letters, values=1:26 )
h$a # 1
h[ "a" ]
h[[ "a" ]]

z <- rep(letters[3:5],2)

h[z] # still with NO duplicates
<hash> containing 3 key-value pair(s).
c : 3
d : 4
e : 5

But seems like it cannot return a vector of values with something like:

h[[z]]
Error in h[[z]] : wrong arguments for subsetting an environment

Otherwise, it would be perfect so that we can get rid of data.frame by using some ‘real’ hash concept.

Thanks!

  • 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-26T15:43:50+00:00Added an answer on May 26, 2026 at 3:43 pm

    To answer your first question: Use match

    df[match(x, df$key), ]
    
        key value
    2     3    52
    3     4    26
    2.1   3    52
    2.2   3    52
    4     5    12
    4.1   5    12
    5     6     1
    5.1   6     1
    5.2   6     1
    5.3   6     1
    

    You should also have a look at Named vectors

    dat <- c(0,52,26,12,1)
    names(dat) <- as.character(c(0,3:6))
    
    dat[as.character(x)]
     3  4  3  3  5  5  6  6  6  6 
    52 26 52 52 12 12  1  1  1  1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is actually a non-critical question, but I get this warning most of the
This is actually a three-part question, which I'll explain below, but the questions are:
Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq,
I have seen code like this (actually seeing another person type it up): catch
I am trying to get coordinates from GPS (this actually gives the values for
I understand that 2 options are available: Non-persistent Persistent But what does this actually
I know this question has been asked several times, but I would like to
Could someone explain in layman terms what this actually does? XmlTextReader textReader = new
If I use INT(12) vs INT(10) or INT(8) what will this actually do in
referring to yesterday's post, this woke me up this morning. Why does this actually

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.