-4

I would like to know how many different species each familly has? Anyone can provide me this code? I am not very familliar with R.

Example Data

enter image description here

merv
  • 67,214
  • 13
  • 180
  • 245
mihailo
  • 1
  • 1

1 Answers1

-1

You have angered us!

For your learning, and the sake of our sanity. please read the rules of stackoverflow before posting. Now for the answer. I googled and got this SO answer: How to count the number of unique values by group?

applying it to your data, first I need to create your data because you have given us an image (not helpful):

week <- c(sample(1:40, size = 20))
family <- c(sample(rep(c("Acrocephalidae", "Sylviidae", "Muscicapidae"), 40), size = 20))
species <- c(sample(rep(c("Acrocephalidae Schoenobaenus", "Sylvia communis", "Erithacus rubetra", "Cettia cetti"), 40), size = 20))           
recapture <- c(sample(rep(0:1, 40), 20))
dat <- data.frame(week, family, species, recapture) 

This just randomly generates similar data to yours. Now we can answer your question:

library(dplyr) #this uses the dplyr package. install first to use
dat %>% group_by(family) %>% summarise(count = n_distinct(species))

Next time please read the rules, do some googling and if you have no idea about a language... do more googling.

Good luck!

Amar
  • 1,340
  • 1
  • 8
  • 20