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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:34:17+00:00 2026-06-18T11:34:17+00:00

If we have his data recentely used here : data <- data.frame(name = rep(letters[1:3],

  • 0

If we have his data recentely used here:

data <- data.frame(name = rep(letters[1:3], each = 3), 
                   var1 = rep(1:9), var2 = rep(3:5, each = 3))

  name var1 var2
1    a    1    3
2    a    2    3
3    a    3    3
4    b    4    4
5    b    5    4
6    b    6    4
7    c    7    5
8    c    8    5
9    c    9    5

we can look for rows where var2 == 4.

data[data[,3] == 4 ,] # equally data[data$var2 == 4 ,]

#  name var1 var2
#4    b    4    4
#5    b    5    4
#6    b    6    4

or rows where both var1 and var2 ==4

data[data[,2] == 4 &  data[,3] == 4,]

#  name var1 var2
#4    b    4    4

what I dont get is why this:

data[ data[ , 2:3 ] == 4 ,]

gives this:

     name var1 var2
4       b    4    4
NA   <NA>   NA   NA
NA.1 <NA>   NA   NA
NA.2 <NA>   NA   NA

#I would still hope to get 
 #  name var1 var2
#4    b    4    4

Where do the NAs come from?

  • 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-18T11:34:19+00:00Added an answer on June 18, 2026 at 11:34 am

    Your data[,2:3]==4 is the following :

    R> data[,2:3]==4
           var1  var2
     [1,] FALSE FALSE
     [2,] FALSE FALSE
     [3,] FALSE FALSE
     [4,]  TRUE  TRUE
     [5,] FALSE  TRUE
     [6,] FALSE  TRUE
     [7,] FALSE FALSE
     [8,] FALSE FALSE
     [9,] FALSE FALSE
    

    Then you try to index the rows of your data frame with this matrix. To do this, R seems to first convert your matrix to a vector :

    R> as.vector(data[,2:3]==4)
     [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
    [12] FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
    

    It then selects the rows of data based on this vector. The 4th TRUE value selects the 4th row, but the three others TRUE values select “out of bounds” rows, so they return NA‘s.

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

Sidebar

Related Questions

I have an application where for each object the user can specify his own
I'm implementing a service where each user must have his own json/document database. Beyond
I have a customer who wants an application for his travels where he can
What I am trying to do is have a user input his data into
here i tried to take name and password from database if the user have
I have a client who understands that his data model is a directed acyclic
i have an array that named detailTexts that having his data from floats: CLLocation
I want to do the following: The user should have his own sub site
I have followed his popular tutorial to connect Android to MySQL: http://www.helloandroid.com/tutorials/connecting-mysql-database It is
I have a client who wants his script to be tweaked for some modifications.

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.