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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:57:20+00:00 2026-06-13T18:57:20+00:00

I have the following data frame: structure(list(Species = 1:4, Ni = c(1, NA, 1,

  • 0

I have the following data frame:

structure(list(Species = 1:4, Ni = c(1, NA, 1, 1), Zn = c(1, 
1, 1, 1), Cu = c(NA, NA, 1, NA)), .Names = c("Species", "Ni", 
"Zn", "Cu"), row.names = c(NA, -4L), class = "data.frame")

and I would like to get a vector containing all the species where Ni = 1, Zn = 1 and Cu = NA. So in this example that would be (1,4)

I thought I could have a try with the R script select * from where, but I can’t seem to install the package RMySQL on RStudio (R version 2.15.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-13T18:57:21+00:00Added an answer on June 13, 2026 at 6:57 pm
    df <- structure(list(Species=1:4,Ni=c(1,NA,1,1),Zn=c(1,1,1,1),Cu=c(NA,NA,1,NA)),
          .Names=c("Species","Ni","Zn","Cu"),row.names=c(NA,-4L),class="data.frame")
    
    with(df, Species[Ni %in% 1 & Zn %in% 1 & Cu %in% NA])
    [1] 1 4
    

    Rather than using Ni == 1 you should use Ni %in% 1, as the former will return NA elements where Ni is NA. Cu %in% NA produces the same result as is.na(Cu).

    with(df, Species[Ni == 1 & Zn %in% 1 & Cu %in% NA])
    [1] 1 NA 4
    

    Note though that Ni == 1 used in subset, as in @MadScone’s answer, does not suffer from this (which came as a surprise to me).

    subset(df, Ni == 1 & Zn == 1 & is.na(Cu), Species)
      Species
    1       1
    4       4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with
Say I have the following R data.frame ZZZ : ( ZZZ <- structure(list(n =
I have the following data frame: id,property1,property2,property3 1,1,0,0 2,1,1,0 3,0,0,1 4,1,1,1 d.f <- structure(list(id
I have the following data frame: structure(list(X1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
I have following data ct<-structure(list(Conc = c(50L, 100L, 150L, 50L, 100L, 150L, 50L, 100L,
I have the following (dummy) data: d <- structure(list(group = structure(c(1L, 1L, 1L, 1L,
I have a similar data frame as follows: mapDF <- structure(list(var = c(11L, 3L,
Suppose you have a data frame with the following structure: df <- data.frame(a=c(1,2,3,4), b=c(job1;job2,
I have written the following code: library(ggplot2) data <- structure(list(x = c(1L, 6L, 3L,
I have data frame that looks like the following models cores time 1 4

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.