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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:54:23+00:00 2026-06-15T19:54:23+00:00

I have the following matrix mat<-read.csv(mat.csv) sel<-c(135, 211) I would like to select the

  • 0

I have the following matrix

mat<-read.csv("mat.csv")
sel<-c(135, 211)

I would like to select the rows in ‘mat’ that correspond to ‘sel’

I do it in the following way:

subset(mat, mat$V2==c(sel))

and I get the following error:

Warning message:
In l[, 2] == c(135, 211) :
  longer object length is not a multiple of shorter object length

And also it only selects one of the two.

  • 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-15T19:54:24+00:00Added an answer on June 15, 2026 at 7:54 pm

    Try this (credits go to Roland)

    mat[mat$V2 %in% sel,]
        X V1  V2 V3 V4  V5 V6 V7 V8 V9 V10
    11 11  1 135  2  7 100  2  0  0  0   0
    15 15  1 211  5  7 100  2  0  0  0   0
    

    from ?'%in% you can read:

        %in% is a more intuitive interface as a binary operator, which returns
    a logical vector indicating if there is a match or not for its left operand.
    

    If you have a logical vector indicating the matching, then you can use it for indexing and selecting the elements you want. In this case mat$V2 %in% sel matches all elements of mat$V2 that are in sel it will give you a logical vector, then using it in mat[row, col] you’ll get ontly those desired elements as in mat[mat$V2 %in% sel,] this means: Give all the columns for those rows which elements meeting the condition mat$V2 %in% sel.

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

Sidebar

Related Questions

I have a matrix 'mat' with two rows of the following form: mat: 1
I have following structure matrix As Dictionary(Of String, Dictionary(Of Class1, Class2)) I would like
I have the following code to convert the type of the matrix using cv::Mat.convertTo()
I have this following numpy matrix that I want to sort in ascending order
I have the following distance matrix in csv format. http://palaeomath.palass.org/images/mds/T1.jpg Using PHP, how could
In my program, I have a file called constants.h that declares the following matrix
suppose I have the following matrix a = 2 NaN NaN 4 NaN 3
Say I have the following matrix: A = randi(10, [6 3]) 7 10 3
In R I have the following matrix (each row represents a bootstrap 95% confidence
Say I have the following similarity matrix : matrix = [[100.0, 66.666666666666671, 61.539999999999999, 59.260000000000005,

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.