1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # un exemple
tab <-
structure(list(Espece = structure(c(2L, 3L, 1L), .Label = c("ecureuil",
"Lievre", "sanglier"), class = "factor"), M1S1 = c(0L, 1L, 1L
), M1S2 = c(1L, 1L, 0L), M1S3 = c(1L, 1L, 1L), M2S1 = c(0L, 0L,
1L), M2S2 = c(0L, 0L, 1L), M2S3 = c(1L, 0L, 0L)), .Names = c("Espece",
"M1S1", "M1S2", "M1S3", "M2S1", "M2S2", "M2S3"), row.names = c("Lievre",
"sanglier", "ecureuil"), class = "data.frame")
# tu peux l'obtenir à partir de read.table
library(tidyr)
library(dplyr)
# si les espèces ne sont pas dans une colonne mais dans les noms des lignes :
tab <- cbind(Espece = rownames(tab), tab)
tab2 <- gather(tab, "methode", "valeur", -1)
tab2 <- tab2 %>% extract(methode, c("Methode", "Site"), regex="^([A-Z]\\d+)([A-Z]\\d+)$") |
Partager