0

I'm a beginner in R and I'm working on a data frame of species occurrence in archipelagos. The data are organised in a data frame where the species is a unit and the islands are two of the many variables.
I need to modify the data producing a new data frame where units are the specimens, linked with a single island where they have been found

The actual data frame is something like this, where "A", "B", "C", "D" are species name and "1", "2" are island names

> species <- c("A", "B", "C", "D")
> island1 <- c("1", "1", " ", "1")
> island2 <- c(" ", "2", "2", "2")
> tab <- data.frame(species, island1, island2)
> tab

    species island1 island2
1       A       1        
2       B       1       2
3       C               2
4       D       1       2

But i have to build this, and specifically I'm interested in the duplication of the species that occur in both the islands

> specimens <- c("A", "B", "B", "C", "D", "D")
> island <- c("1", "1", "2", "2", "1", "2")

> tab <- data.frame(species, island)
> tab
  specimens island
1       A      1
2       B      1
3       B      2
4       C      2
5       D      1
6       D      2
 

Are there any functions and application methods that can allow me to this in rapid way? I have many data frame to reorganize and I'm struggling to find the right way to do it.

Thanks to everyone who can spend some time to help me

0 Answers0