0

I am new in R and try to filter a whole row with all data by a string. I want to save the filtered rows as a new variable or dataframe. I want to use the library(dplyr) My dataframe "Anatomy" looks like this:

  Species Value1 Value2
1 Species1      1     NA
2 Species2      2     NA
3 species3      3     NA

I tried now:

Species1<-data.frame(filter(Anatomy, Species == "Species1"))

But my output is always only the headers.

Species Value1 Value2

Could you help me please?

  • `Species1 <- filter(Anatomy, Species == "Species1")` or `Species1 <- Anatomy[Anatomy$Species == "Species1", ]` – nghauran Feb 28 '19 at 12:55

1 Answers1

0

I am not sure about how to use dplyr::filter() to accomplish what you want, but you can simply do the following to get only the Species1 data

new_df <- df[df$Species=='Species1', ]
Nate
  • 10,361
  • 3
  • 33
  • 40
D.Sanders
  • 98
  • 6