How to Filter Rows in a Data Frame Using the dplyr Filter function

Поділитися
Вставка
  • Опубліковано 3 гру 2024

КОМЕНТАРІ • 16

  • @tiagovieira3744
    @tiagovieira3744 Рік тому

    These classes are just great. Really helpful! Thanks a lot!

    • @weecology
      @weecology  Рік тому

      Thanks! So glad they are helpful!

  • @Arguments_only
    @Arguments_only Рік тому

    great content! Thank you :)

  • @zainabkhan2475
    @zainabkhan2475 2 роки тому

    thanks a lot!

  • @FaithMueniKioko
    @FaithMueniKioko 5 місяців тому +1

    am looking at the data which i want to see the children how have never gotten every vaccination and i on want to select the row with variable "no" in 26 columns how can i go about it

    • @weecology
      @weecology  4 місяці тому

      If the columns are all next to one another you can use something like:
      filter(dataframe, across(10:36, ~ . == "no"))
      Where 10 is the column number of the first column in the block and 36 is the number of the last column in the block.
      If they aren't all grouped together you can still use across, but you have to name the columns:
      df_filtered %
      filter(across(c(col1, col2, col3, col4, ... col26), ~ . == "no"))

  • @CanDoSo_org
    @CanDoSo_org 2 роки тому

    Hi, can we filter species_id all start with "D" with *? thanks.

    • @weecology
      @weecology  2 роки тому +1

      You can do this by combing dplyr with the stringr package. E.g.,:
      library(dplyr)
      library(stringr)
      df = data.frame(species = c("DM", "DO", "PP"), count = c(1, 2, 3))
      filter(df, str_detect(species, "^D"))
      The ^D means "starts with D"

    • @CanDoSo_org
      @CanDoSo_org 2 роки тому +1

      @@weecology Many thanks. "filter(grepl("D", species,)) " works as well.😀

  • @NayeonGoddes
    @NayeonGoddes Рік тому

    This code always return to me 0 observations and 12 variables, I don't know why, I don't know what to do

    • @weecology
      @weecology  Рік тому

      Can you paste the specific code here that isn’t working the way you expect?

    • @NayeonGoddes
      @NayeonGoddes Рік тому

      @@weecology SampleRancagua = filter(SUBSET, Comuna == "Graneros")
      Thank youuu :(

    • @weecology
      @weecology  Рік тому

      OK, so just to check. SUBSET is a a data frame, it has a column named Comuna, and there is at least one row in that column where the value is “Graneros”?

    • @weecology
      @weecology  Рік тому +2

      The most common cause of zero rows returned is either a typo in the value given in “” or a difference in the capitalization, since either of these can result in no matches

    • @NayeonGoddes
      @NayeonGoddes Рік тому

      Yes, exaclty :(@@weecology