-2

I've built a data frame with information about 724 plastics (size, colour, weight, etc.) found in seabirds' stomachs. Now I want to create some sort of "filter" so i can analyze the data from the birds such as how many plastics were found in each stomach, the total amount of plastic weight extracted from each bird, or how many birds from each species I have in the data frame (the data frame includes the bird's ID number in which each plastic was found).

I have no idea how to make this "filter" and i cannot find any help by Googling my question or searching it here. What command/s should i use?

I'll link a sample of the data frame so you can see it better. Each column, from left to right, indicates plastic ID number, plastic size, species ID, bird ID number, plastic weight and plastic color.

Tino
  • 2,091
  • 13
  • 15
  • 1
    have a look on dplyr. Here is a tutorial, which also considers filtering: http://genomicsclass.github.io/book/pages/dplyr_tutorial.html – Linus Dec 24 '17 at 17:55
  • this is simble base R: for example the number of birds in each species `table(data$species)` – Onyambu Dec 24 '17 at 17:58
  • For the total amount of plastic from each bad, use `with(data,tapply(weight,ID,sum))` or you can use `by` or `aggregate` – Onyambu Dec 24 '17 at 18:03
  • 2
    Possible duplicate of [Filter data.frame rows by a logical condition](https://stackoverflow.com/questions/1686569/filter-data-frame-rows-by-a-logical-condition) – dmi3kno Dec 25 '17 at 02:38

1 Answers1

1

Imagine your dataset is called DF:

library(tidyverse)
DF %>% 
    filter(Especie=="CALDIO")

and you may filter only birds of Caldio "especie", and so on. Just google tidyverse package and dplyr.

Whether you are interested in plastic amount per species:

Table_by_species <- DF %>% 
    group_by(Especie) %>%
    summarise(Total_Weight=sum(`weight_plastic`,na.rm=T))
Scipione Sarlo
  • 1,470
  • 1
  • 17
  • 31