0

so I'm trying to find the total amount of each class in the Genus column, the following dataframe is shown below:

Genus/Species Dataframe

But it returns values of how many times each Genus is repeating, not it's total amount of the species observed.

I want a dataframe that looks like this:

Genus - Arachnida Total Sum - (Total amount of Arachnida)

Thank you for whoever replies! (This is my first post, English is my second language so hopefully someone understands!)

I've tried using dplyr's function of count like:

BIO205 %>% count(Genus)

But it returns values of how many times each Genus is repeating, not it's total.

Like if I did BIO205 %>% count(Genus), it would return with

Returning Dataframe

This is indicating that the word Arachnida is repeating 21 times.

1 Answers1

0

So it seems like you are trying to sum all the total values for each genus. If so group_by() is what you want. Here is a reprex:

library(dplyr)

data("iris")

iris %>%
    group_by(Species) %>%
    summarise(sum_col = sum(Sepal.Length))

The above code is grouping the data by species, followed by summing all the sepal lengths for each species. In your case, what I would try is the following code:

library(dplyr)

BIO205 %>%
    group_by(Genus) %>%
    summarise(sum_col = sum(Total))

Hope this helps.

SpikyClip
  • 154
  • 10