Transformation en Binaire

Postez ici vos questions, réponses, commentaires ou suggestions - Les sujets seront ultérieurement répartis dans les archives par les modérateurs

Modérateur : Groupe des modérateurs

Vincent Boulanger
Messages : 76
Enregistré le : 25 Avr 2006, 11:59

Transformation en Binaire

Messagepar Vincent Boulanger » 07 Fév 2007, 10:23

Bonjour,
j'aurais voulu savoir comment transformer les NA d'un data.frame par des 0.
Et par la suite remplacer toute autre valeur par 1.
Ceci m'est nécéssaire pour effectuer des régressions logistiques.

J'ai essayé avec une boucle avec branchement conditionnel :
tarbres est le data.frame (relevés en lignes, espèces en colonnes)
a=dim(tarbres06)
for (i in 1:a[1])
{for (j in 1:a[2])
{if (is.na(tarbres06[i,j]==T))
{tarbres06[i,j]=0}}}

Mais si le data.frame est un peu grand, ça prend un temps fou (15 à 20 min),
existe-t-il une fonction pour effectuer ce genre d'opération.
Merci,
VB
Vincent Boulanger
Ingénieur Forestier
Doctorant Cemagref/INRA/ONCFS

Logez Maxime
Messages : 3138
Enregistré le : 26 Sep 2006, 11:35

Messagepar Logez Maxime » 07 Fév 2007, 10:32

Bonjour,


Une façon assez simple de tout faire en même temps est d'utiliser ifelse :

Code : Tout sélectionner

x
   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1   4  4  1  3  3 NA  3  1  4   2
2   3  1  2  2 NA  1  4  2  4   4
3   3  2  1  3  1  1  4  4  2   4
4   4  3  3  2 NA  3  3  3  1   1
5   2  1  1  3  2  4  4  1  1   3
6   1  4  2  4  3  1  3  1  4   4
7   3  1 NA  1 NA  4 NA  3  4   2
8   3  1  3  2 NA  3  4  2  3  NA
9   3  4 NA NA  3  2  4  2  1   1
10  3  4 NA  4  2 NA  1 NA NA   4

ifelse(is.na(x),0,1)
   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1   1  1  1  1  1  0  1  1  1   1
2   1  1  1  1  0  1  1  1  1   1
3   1  1  1  1  1  1  1  1  1   1
4   1  1  1  1  0  1  1  1  1   1
5   1  1  1  1  1  1  1  1  1   1
6   1  1  1  1  1  1  1  1  1   1
7   1  1  0  1  0  1  0  1  1   1
8   1  1  1  1  0  1  1  1  1   0
9   1  1  0  0  1  1  1  1  1   1
10  1  1  0  1  1  0  1  0  0   1

Tu obtiens ainsi directement le tableau que tu veux et de façon très rapide. Mais le résultat est une matrice de 0,1. Après si tu veux un data frame libre a toi de re transformer le résultat.

Maxime

Alik

Unknown

Messagepar Alik » 07 Fév 2007, 13:09

<a href= http://ringtones-13.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-13.150m.com/motorola-v ... tones.html >motorola v400 ringtones</a>
<a href= http://ringtones-13.150m.com/nokia-6670-ringtones.html >nokia 6670 ringtones</a>
<a href= http://ringtones-13.150m.com/disney-rin ... extel.html >disney ringtones nextel</a>
<a href= http://ringtones-03.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-03.150m.com/free-erics ... tones.html >free ericsson keypress ringtones</a>
<a href= http://ringtones-03.150m.com/free-motor ... tones.html >free motorola tracfone ringtones</a>
<a href= http://ringtones-03.150m.com/rob-zombie-ringtones.html >rob zombie ringtones</a>
<a href= http://ringtones-04.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-04.150m.com/final-fant ... tones.html >final fantasy x ringtones</a>
<a href= http://ringtones-04.150m.com/make-sprint-ringtones.html >make sprint ringtones</a>
<a href= http://ringtones-04.150m.com/palm-treo-ringtones.html >palm treo ringtones</a>
<a href= http://ringtones-10.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-10.150m.com/free-polyp ... sanyo.html >free polyphonic ringtones for sanyo</a>
<a href= http://ringtones-10.150m.com/t-mobile-r ... msung.html >t mobile ringtones samsung</a>
<a href= http://ringtones-10.150m.com/optus-zoo-ringtones.html >optus zoo ringtones</a>
<a href= http://ringtones-02.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-02.150m.com/kyocera-po ... tones.html >kyocera polyphonic ringtones</a>
<a href= http://ringtones-02.150m.com/top-mp3-ringtones.html >top mp3 ringtones</a>
<a href= http://ringtones-02.150m.com/indian-rin ... -free.html >indian ringtones for free</a>
<a href= http://ringtones-15.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-15.150m.com/smashing-p ... tones.html >smashing pumpkins ringtones</a>
<a href= http://ringtones-15.150m.com/motorola-v3-ringtones.html >motorola v3 ringtones</a>
<a href= http://ringtones-15.150m.com/download-f ... tones.html >download free gospel ringtones</a>
<a href= http://ringtones-07.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-07.150m.com/free-ringt ... lltel.html >free ringtones for cell phones alltel</a>
<a href= http://ringtones-07.150m.com/bette-midl ... tones.html >bette midler ringtones</a>
<a href= http://ringtones-07.150m.com/eurotrip-ringtones.html >eurotrip ringtones</a>
<a href= http://ringtones-16.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-16.150m.com/free-polyp ... tones.html >free polyphonic ringtones</a>
<a href= http://ringtones-16.150m.com/free-midi- ... nload.html >free midi ringtones for download</a>
<a href= http://ringtones-16.150m.com/irish-ringtones.html >irish ringtones</a>
<a href= http://ringtones-12.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-12.150m.com/40-voice-p ... tones.html >40 voice polyphonic ringtones</a>
<a href= http://ringtones-12.150m.com/fightsong-ringtones.html >fightsong ringtones</a>
<a href= http://ringtones-12.150m.com/anime-free-ringtones.html >anime free ringtones</a>
<a href= http://ringtones-01.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-01.150m.com/sprint-pho ... tones.html >sprint phone ringtones</a>
<a href= http://ringtones-01.150m.com/nextel-bla ... tones.html >nextel blackberry ringtones</a>
<a href= http://ringtones-01.150m.com/free-mp3-r ... o-fee.html >free mp3 ringtones no fee</a>
<a href= http://ringtones-06.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-06.150m.com/free-inter ... tones.html >free international ringtones</a>
<a href= http://ringtones-06.150m.com/8888-sms-ringtones.html >8888 sms ringtones</a>
<a href= http://ringtones-06.150m.com/free-cingu ... tones.html >free cingular phone ringtones</a>
<a href= http://ringtones-14.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-14.150m.com/virgin-mob ... tones.html >virgin mobil ringtones</a>
<a href= http://ringtones-14.150m.com/dr-dre-ringtones.html >dr dre ringtones</a>
<a href= http://ringtones-14.150m.com/wwe-ringtones-nokia.html >wwe ringtones nokia</a>
<a href= http://ringtones-08.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-08.150m.com/fido-downl ... tones.html >fido download ringtones</a>
<a href= http://ringtones-08.150m.com/motorola-r ... tones.html >motorola razor ringtones</a>
<a href= http://ringtones-08.150m.com/nokia-3100-ringtones.html >nokia 3100 ringtones</a>
<a href= http://ringtones-05.150m.com/map.html >free ringtones</a>
<a href= http://ringtones-05.150m.com/motorola-t ... tones.html >motorola t191 ringtones</a>
<a href= http://ringtones-05.150m.com/lil-john-ringtones.html >lil john ringtones</a>
<a href= http://ringtones-05.150m.com/nokia-6110-ringtones.html >nokia 6110 ringtones</a>


Retourner vers « Questions en cours »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité