Modérateur : Groupe des modérateurs
Code : Tout sélectionner
.data <- read.table(header = TRUE, text = "Ferme E F G A D E
Apionidae 0 0 0 0 0 0
Araignées 2 17 1 9 18 0
Chrysomelidae 0 5 0 0 1 0
Chrysopidae 0 0 0 0 0 0
Curculionidae 0 0 0 0 1 0
Elateridae 0 5 0 4 0 0
Forficule 0 0 0 0 0 0
Limaces/Escargots 1 0 0 2 2 0
Mecoptère 0 0 0 0 0 0
Opilion 0 4 0 0 1 0
Puceron 0 0 0 1 0 0
Staphylinidae 0 5 0 1 1 0
Syrphidae 0 0 0 1 0 0")
Code : Tout sélectionner
duplicated2 <- function (x, bothWays = TRUE, ...) {
if (bothWays) {
duplicated(x, ...) | duplicated(x, fromLast = TRUE, ...)
} else {
duplicated(x, ...)
}
}
col_dup <- duplicated2(colnames(.data))
names(col_dup) <- colnames(.data)
for (idup in unique(names(which(col_dup)))) {
pos <- which(col_dup)[grep(idup, names(which(col_dup)))]
.data[, pos[1]] <- rowSums(.data[, pos])
.data[, pos[-1]] <- NULL
}
.data
#> Ferme E F G A D
#> 1 Apionidae 0 0 0 0 0
#> 2 Araignées 2 17 1 9 18
#> 3 Chrysomelidae 0 5 0 0 1
#> 4 Chrysopidae 0 0 0 0 0
#> 5 Curculionidae 0 0 0 0 1
#> 6 Elateridae 0 5 0 4 0
#> 7 Forficule 0 0 0 0 0
#> 8 Limaces/Escargots 1 0 0 2 2
#> 9 Mecoptère 0 0 0 0 0
#> 10 Opilion 0 4 0 0 1
#> 11 Puceron 0 0 0 1 0
#> 12 Staphylinidae 0 5 0 1 1
#> 13 Syrphidae 0 0 0 1 0
Code : Tout sélectionner
Ferme A B C D E F G
1 Acupalpus_elegans 1 0 NA 0 0 0 0
2 Acupalpus_meridianus 1 0 NA 0 0 1 0
3 Agonum_muelleri 2 0 NA 0 0 0 0
4 Amara_aenea 15 0 NA 0 0 6 0
5 Amara_anthobia 1 0 NA 0 0 0 0
6 Amara_bifrons 3 0 NA 0 0 0 0
7 Amara_communis 2 0 NA 0 0 2 0
8 Amara_familiaris 2 0 NA 0 0 0 0
9 Amara_montivaga 0 0 NA 0 0 0 0
10 Amara_nitida 2 0 NA 0 0 0 0
11 Amara_ovata 0 0 NA 0 0 0 0
12 Amara_plebeja 0 0 NA 0 0 0 0
13 Amara_similata 0 0 NA 0 0 0 0
14 Anchomenus_dorsalis 2 0 NA 0 0 1 0
15 Anisodactylus_binotatus 3 0 NA 0 0 0 0
16 Anisodactylus_signatus 0 0 NA 0 0 0 0
17 Anthracus_consputus 0 0 NA 0 0 0 0
18 Badister_peltatus 0 0 NA 0 0 0 0
19 bembidion_? 0 0 NA 0 0 0 0
20 Bembidion_lampros 0 0 NA 0 0 0 0
21 Bembidion_quadrimaculatum 0 0 NA 0 0 0 0
22 Bembidion_tetragrammum_ 0 0 NA 0 0 0 0
23 Brachinus_explodens 2 0 NA 0 0 2 0
24 Brachinus_sclopeta 11 0 NA 0 0 9 0
25 Carabus_nemoralis 0 0 NA 0 0 0 0
26 Cicindela_campestris 0 0 NA 0 0 0 0
27 Clivina_gr_fossor 1 0 NA 0 0 0 0
28 Demetrias_atricapillus 0 0 NA 0 0 0 0
29 Harpalus_affinis 21 0 NA 0 0 4 0
30 Harpalus_anxius 0 0 NA 0 0 0 0
31 Harpalus_atratus 0 0 NA 0 0 0 0
32 Harpalus_cupreus 0 0 NA 0 0 0 0
33 Harpalus_dimidiatus 5 0 NA 0 0 0 0
34 Harpalus_distiguendus 13 0 NA 0 0 4 0
35 Harpalus_latus 0 0 NA 0 0 0 0
36 Harpalus_picipennis 0 0 NA 0 0 0 0
37 Harpalus_rubripes 1 0 NA 0 0 0 0
38 Harpalus_smaragdinus 0 0 NA 0 0 0 0
39 Harpalus_tardus 11 0 NA 0 0 2 0
40 Leistus_ferrugineus 1 0 NA 0 0 0 0
41 Leistus_spinibarbis 0 0 NA 0 0 0 0
42 Metalina_lampros 0 0 NA 0 0 0 0
43 Metellina_properans 17 0 NA 0 0 5 0
44 Microlestes_minutulus 0 0 NA 0 0 0 0
45 Microlestes_sp 0 0 NA 0 0 0 0
46 Nebria_brevicollis 5 0 NA 0 0 2 0
47 Nebria_salina 6 0 NA 0 0 2 0
48 Notiophilus_biguttatus 0 0 NA 0 0 0 0
49 Notiophilus_rufipes 1 0 NA 0 0 0 0
50 Ocydromus_deletus 0 0 NA 0 0 0 0
51 Ocys_harpaloides 0 0 NA 0 0 0 0
52 Ophonus_azureus 0 0 NA 0 0 0 0
53 Ophonus_subquadratus 1 0 NA 0 0 0 0
54 Ophorius_rufibarbis 0 0 NA 0 0 0 0
55 Paradromius_linearis 0 0 NA 0 0 0 0
56 Paraphonus_maculicornis 1 0 NA 0 0 1 0
57 Paraphonus_maculiformis 0 0 NA 0 0 0 0
58 Patrobus_australis 0 0 NA 0 0 0 0
59 Philochthus_mannerheimii 0 0 NA 0 0 0 0
60 Phyla_obtusata 3 0 NA 0 0 0 0
61 Poecilus_cupreus 76 0 NA 0 0 28 0
62 Pseudoophonus_rufipes 2 0 NA 0 0 0 0
63 Semioophonus_signiaticornis 1 0 NA 0 0 0 0
64 Trechus_gr_quadristriatus 2 0 NA 0 0 0 0
Code : Tout sélectionner
Ferme A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G
Acupalpus_elegans 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 1 0 0 0 0 0
Acupalpus_meridianus 0 0 NA 0 0 1 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Agonum_muelleri 0 0 NA 0 0 0 0 0 0 NA 0 0 2 0 0 0 0 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Amara_aenea 0 0 NA 0 0 6 0 1 0 NA 0 1 4 0 0 0 NA 0 2 0 0 0 0 NA 0 1 0 0 0 0 0 0 0 0 0
Amara_anthobia 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0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rufibarbis 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Paradromius_linearis 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Paraphonus_maculicornis 0 0 NA 0 0 1 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Paraphonus_maculiformis 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Patrobus_australis 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Philochthus_mannerheimii 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Phyla_obtusata 0 0 NA 0 0 0 0 2 0 NA 1 0 0 0 0 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Poecilus_cupreus 3 0 NA 0 0 28 0 2 0 NA 0 0 27 1 0 0 NA 0 0 14 0 0 0 NA 0 1 0 0 0 0 0 0 0 0 0
Pseudoophonus_rufipes 0 0 NA 0 0 0 0 0 0 NA 1 0 0 0 1 0 NA 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Semioophonus_signiaticornis 0 0 NA 0 0 0 0 0 0 NA 0 0 1 0 0 0 0 0 0 0 0 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Trechus_gr_quadristriatus 0 0 NA 0 0 0 0 0 0 NA 0 0 0 1 0 0 NA 0 0 0 1 0 0 NA 0 0 0 0 0 0 0 0 0 0 0
Code : Tout sélectionner
.data <- read.table(file = "data.txt", header = TRUE, check.names = FALSE)
duplicated2 <- function (x, bothWays = TRUE, ...) {
if (bothWays) {
duplicated(x, ...) | duplicated(x, fromLast = TRUE, ...)
} else {
duplicated(x, ...)
}
}
col_dup <- duplicated2(colnames(.data))
names(col_dup) <- colnames(.data)
for (idup in unique(names(which(col_dup)))) {
pos <- which(col_dup)[grep(idup, names(which(col_dup)))]
.data[, pos[1]] <- rowSums(.data[, pos], na.rm = TRUE)
}
.data <- .data[, !duplicated(colnames(.data))]
Retourner vers « Questions en cours »
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité