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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:57:11+00:00 2026-06-17T20:57:11+00:00

Possible Duplicate: select some values of a row in a matrix R subset a

  • 0

Possible Duplicate:
select some values of a row in a matrix
R subset a data frame with multiple keys

Say I have a list

> test

  V1    V2   V3
1  1   one  uno
2  2   two duos
3  3 three tres
4  4 four cuatro

and a vector a<-c("one","three").

I want to get the subset of the list test where the element of the second column are from vector a.

So in this case answer should be something like,

  V1    V2   V3
1  1   one  uno
2  3 three tres

I want something on the lines of
test[test[,2]=="one",] but for multiple values. How to do that?

  • 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-17T20:57:12+00:00Added an answer on June 17, 2026 at 8:57 pm

    What you’re looking for is %in% (although you could also use match and subset). See below.

    df <- data.frame(V1=1:4, V2=c("one", "two", "three", "four"), stringsAsFactors = FALSE)
    fil <- c("one", "three")
    
    > df
    #   V1    V2
    # 1  1   one
    # 2  2   two
    # 3  3 three
    # 4  4  four
    
    > fil
    # [1] "one"   "three"
    
    # subset df by column V2 using fil
    
    # using %in%
    df[df$V2 %in% fil, ]
    
    # using subset
    subset(df, V2 %in% fil)
    
    # using match
    df[!is.na(match(df$V2, fil)), ] # (or) 
    df[which(!is.na(match(df$V2, fil))), ]
    
    # all gives
    #   V1    V2
    # 1  1   one
    # 3  3 three
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How disable Copy, Cut, Select, Select All in UITextView I have some
Possible Duplicate: How to access object using dynamic key? I have multiple select with
Possible Duplicate: How to select rows where multiple joined table values meet selection criteria?
Possible Duplicate: Test for NA and select values based on result Suppose you have
Possible Duplicate: jquery: select the last 4 items in the list jQuery has the
Possible Duplicate: How do I randomly select an item from a list using Python?
Possible Duplicate: make drop down list item unselectable I have an asp.net dropdownlist and
Possible Duplicate: need help with some stored procedure plz ERROR:- A SELECT statement that
Possible Duplicate: Getting the minimum of two values in sql Okay what I Have
Possible Duplicate: Jquery selectors on custom data attributes on HTML5 How can I select

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.