-1

I have a dataframe with 10 columns. One column gives bird species' names. There's actually 300 species but I'm just interested in 200 of them. I would like to keep only the information about this 200 species.

Screenshot of my table: https://i.stack.imgur.com/OcJyI.png

I can't just write : filter(Species == "Mallard" & Species == "Wood-pigeon")

I have a matrix with all the 200 selected species. But, I don't know how to use this matrix to select to relevant rows in my dataframe. Is it possible with subset/filter/etc function to select rows based on a matrix?

What are the correct codes please ?

TarJae
  • 72,363
  • 6
  • 19
  • 66
Amy_Fr
  • 13
  • 1
  • Does this answer your question? [Filter data.frame rows by a logical condition](https://stackoverflow.com/questions/1686569/filter-data-frame-rows-by-a-logical-condition) – user438383 Apr 03 '21 at 20:22

1 Answers1

0

The == with & is not going to work anyway as we don't find the different 'Species' in the same cell. With that code, it would be | instead of &. But, this can be done more easily with %in% on a vector of values e.g.

subset(df1, Species %in% c("Mallard", "Wood-pigeon"))

the

c("Mallard", "Wood-pigeon")

can be extended to any number of Species

akrun
  • 874,273
  • 37
  • 540
  • 662