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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:49:44+00:00 2026-06-17T14:49:44+00:00

I have a matrix: 1 3 NA 1 2 0 1 7 2 1

  • 0

I have a matrix:

1 3  NA
1 2  0
1 7  2
1 5  NA
1 9 5
1 6  3
2 5  2
2 6  1
3 NA  4
4 2  9
...

I would like to select those elements for each number in the first column to which the corresponding value in the second column has an NA in its own second column.

So the search would go the following way:

  1. look up number in the first column: 1.
  2. check corresponding values in second column: 3,2,7,5,9,6…
  3. look up 3,2,7,5,9,6 in first column and see if they have NA in their
    second column

The result in the above case would be:

>3 NA  4<

Since this is the only value which has NA in its own second row.

Here’s what I want to do in words:

  1. Look at the number in column one, I find ‘1’.

  2. What numbers does 1 have in its second column: 3,2,7,5,9,6

  3. Do these numbers have NA in their own second column? yes, 3 has an NA

  4. I would like it to return those numbers not row numbers.

  5. the result would be the subset of the original matrix with those rows which satisfy the condition.

This would be the matlab equivalent, where i is the number in column 1:

isnan(matrix(matrix(:,1)==i,2))==1) 
  • 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-17T14:49:45+00:00Added an answer on June 17, 2026 at 2:49 pm

    Using by, to get the result by group of column 1, assuming dat is your data frame

    by(dat,dat$V1,FUN=function(x){
                      y <- dat[which(dat$V1 %in% x$V2),]
                      y[is.na(y$V2),]
    })
    
    dat$V1: 1
      V1 V2 V3
    9  3 NA  4
    -------------------------------------------------------------------------------- 
    dat$V1: 2
    [1] V1 V2 V3
    <0 rows> (or 0-length row.names)
    -------------------------------------------------------------------------------- 
    dat$V1: 3
    [1] V1 V2 V3
    <0 rows> (or 0-length row.names)
    -------------------------------------------------------------------------------- 
    dat$V1: 4
    [1] V1 V2 V3
    <0 rows> (or 0-length row.names)
    

    EDIT

    Here I trie to do the same function as matlab command:

    here the R equivalent of matlab

      isnan(matrix(matrix(:,1)==i,2))==1)   ## what is i here 
    
      is.na(dat[dat[dat[,1]==1,2],])        ## R equivalent , I set i =1
    
         V1    V2    V3
    3 FALSE FALSE FALSE
    2 FALSE FALSE FALSE
    7 FALSE FALSE FALSE
    5 FALSE FALSE FALSE
    9 FALSE  TRUE FALSE
    6 FALSE FALSE FALSE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix from which I would like to select an observation together
Possible Duplicate: Select only the first rows for each unique value of a column
I have the following matrix mat<-read.csv(mat.csv) sel<-c(135, 211) I would like to select the
I have a matrix of one column and 6 rows. I would like to
I have a large matrix from which I would like to randomly extract a
I have a triangular matrix and would like to loop through all the elements
I have a matrix mat and would like to calculate the mean of the
I have matrix (a) with (1:10),<10 x 1> double. I would like to copy
I have a matrix in R that I would like to take a single
I'm using Numpy and have a 7x12x12 matrix whose values I would like to

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.