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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:52:55+00:00 2026-06-13T20:52:55+00:00

The match(x, y) function is perfect to search the elements of the vector x

  • 0

The match(x, y) function is perfect to search the elements of the vector x within the elements of vector y. But what is an efficient and easy way to do the similar job when y is a list of vectors – of possibly different lengths?

I mean the result should be a vector of the same length as x, and the i-th element should be the first member of y that contains the i-th element of x, or NA.

  • 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-13T20:52:56+00:00Added an answer on June 13, 2026 at 8:52 pm

    To find the element of y in which each element of x (first) occurs, try this:

    ## First, a reproducible example
    set.seed(44)
    x <- letters[1:25]
    y <- replicate(4, list(sample(letters, 8)))
    y
    # [[1]]
    # [1] "t" "h" "m" "n" "a" "d" "i" "b"
    # 
    # [[2]]
    # [1] "c" "l" "z" "a" "s" "d" "i" "u"
    # 
    # [[3]]
    # [1] "b" "k" "e" "g" "o" "i" "h" "j"
    # 
    # [[4]]
    # [1] "g" "i" "f" "r" "h" "w" "l" "o"
    
    ## Find the element of y first containing the letters a-j
    breaks <- c(0, cumsum(sapply(y, length))) + 1 
    findInterval(match(x, unlist(y)), breaks)
    # [1]  1  1  2  1  3  4  3  1  1  3  3  2  1  1  3 NA NA  4  2  1  2 NA  4 NA NA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a budget using a Match function, but I can't
I'd like to use regular expressions in selecting elements using the match function. I'd
So, here is the function for pre-filtering CHILD: function(match){ if ( match[1] === nth
I wrote a function to match fingerprint templates using VC++.NET. Now I want to
I'm using this function: preg_match_all('/((\d{9})\.html)/s', $content, $results); It works fine but i just want
How can I use the startswith function to match any alpha character [a-zA-Z]. For
When assigning a function to a variable, why does the compiler require a perfect
// I have make some change but preg_match function doesn't work and echo Work.
when this function was called it gave the message Warning: preg_match() [function.preg-match]: No ending
I keep getting this error: Warning: preg_match() [function.preg-match]: Unknown modifier 't' in D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php on

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.