I am new to the R environment, and I would like to improve my "Manipulation data" skills. I have this dataset:
structure(list(taxon = c("Acroloxus lacustris", "Ancylus fluviatilis",
"Ancylus fluviatilis", "Asellus aquaticus", "Asellus aquaticus",
"Asellus aquaticus", "Bithynia tentaculata", "Bryozoa Gen. sp.",
"Chironomidae Gen. sp.", "Ephydatia fluviatilis", "Erpobdella octoculata",
"Erpobdella octoculata", "Erpobdella octoculata", "Glossiphonia complanata",
"Physella acuta", "Plumatella fungosa", "Plumatella fungosa",
"Plumatella repens", "Radix balthica/labiata", "Radix balthica/labiata",
"Radix balthica/labiata", "Sphaerium corneum", "Spongilla lacustris",
"Spongillidae Gen. sp.", "Tubificidae Gen. sp."), year = c(1971,
1969, 1971, 1968, 1969, 1971, 1971, 1971, 1969, 1971, 1968, 1969,
1971, 1971, 1971, 1968, 1971, 1971, 1968, 1969, 1971, 1971, 1969,
1971, 1971), abundance = c(12.5714285714286, 6, 15.5, 1, 13,
100.333333333333, 2.11111111111111, 13, 6, 7, 20, 42.5, 22.875,
1, 1, 20, 3.5, 2.66666666666667, 20, 42.5, 17.5789473684211,
65, 6, 42.5, 1)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -25L), groups = structure(list(taxon = c("Acroloxus lacustris",
"Ancylus fluviatilis", "Asellus aquaticus", "Bithynia tentaculata",
"Bryozoa Gen. sp.", "Chironomidae Gen. sp.", "Ephydatia fluviatilis",
"Erpobdella octoculata", "Glossiphonia complanata", "Physella acuta",
"Plumatella fungosa", "Plumatella repens", "Radix balthica/labiata",
"Sphaerium corneum", "Spongilla lacustris", "Spongillidae Gen. sp.",
"Tubificidae Gen. sp."), .rows = structure(list(1L, 2:3, 4:6,
7L, 8L, 9L, 10L, 11:13, 14L, 15L, 16:17, 18L, 19:21, 22L,
23L, 24L, 25L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -17L), .drop = TRUE))
I would like to reorder this data set to the this format:
columns : Species1, species 2, Species 3 .... Rows: years ( 1968, 1969 and 1971, i.e. 3 rows) As you can note not all species appear for all years Looks like the next:
Sp1 Sp2...
1968 1 0
1969 0 45
1971 10 0
But I don't know how to reorder it. I assume that %>% t()
or mutate()
could be useful...
All help its appreciate, thanks for your time.