Bonsoir,
Voici à quoi ressemble ma matrice IndexType :
Index Type
[1,] 389 1
[2,] 975 2
[3,] 1602 1
[4,] 2285 2
[5,] 2676 1
[6,] 3000 2
[7,] 3684 1
[8,] 6830 1
[9,] 8318 1
[10,] 9046 1
J'effectue la boucle suivante :
Et cela me donne ce résultat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Index1 <- c() Index2l <- c() for (z in 1:(nrow(IndexType)-1)){ if(IndexType[z,2] == 2 & IndexType[z,2] > IndexType[z+1,2] ) { IndexA[z] <- IndexType[z,1] IndexB[z] <- IndexType[z+1,1]} }
> IndexA
[1] NA 975 NA 2285 NA 3000
> IndexB
[1] NA 1602 1602 2676 2676 3684 3684
-> Pourquoi avoir des NA dans Index A (et pas pour les 4 dernières lignes) ? Pourquoi avoir des répétitions de certaines valeurs dans IndexB ?
Merci d'avance
Partager