Thanks very much for your help. I remain puzzled by the original behavior of reshape though... Does anyone have an explanation to this ?
Regards, David -----Message d'origine----- De : Gabor Grothendieck [mailto:[EMAIL PROTECTED] Envoyé : jeudi 3 mai 2007 19:27 À : GOUACHE David Cc : [email protected] Objet : Re: [R] reshape question Here is a minor improvement (cn and nm as before): reshape(tab, direction = "long", varying = nm, v.names = names(nm)) On 5/3/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Try this: > > cn <- names(tab) > nm <- list(Date = grep("Date_", cn, value = TRUE), > Variable = grep("Variable", cn, value = TRUE), > Valeur = grep("Valeur", cn, value = TRUE) > ) > reshape(tab, direction = "long", varying = nm) > > > On 5/3/07, GOUACHE David <[EMAIL PROTECTED]> wrote: > > Hello all, > > > > A quick question concerning a behavior of reshape I fail tu understand, > > probably something obvious but I just can't see it. > > > > With the following data frame further referred to as tab : > > > > Variete;Semis.Date;Date_Mesure.1;Variable_Mesure.1;Valeur_Mesure.1;Date_Mesure.2;Variable_Mesure.2;Valeur_Mesure.2;Date_Mesure.3;Variable_Mesure.3;Valeur_Mesure.3;Date_Mesure.4;Variable_Mesure.4;Valeur_Mesure.4;Date_Mesure.5;Variable_Mesure.5;Valeur_Mesure.5;Date_Mesure.6;Variable_Mesure.6;Valeur_Mesure.6;Date_Mesure.7;Variable_Mesure.7;Valeur_Mesure.7;Date_Mesure.8;Variable_Mesure.8;Valeur_Mesure.8;Date_Mesure.9;Variable_Mesure.9;Valeur_Mesure.9;Date_Mesure.10;Variable_Mesure.10;Valeur_Mesure.10 > > A;22/10/2004;38527;Partie > > aérienne.Verse;3.23;38516;Grain.Humidité;0.71;38523;Grain.Humidité;0.67;38526;Grain.Humidité;0.61;38530;Grain.Humidité;0.56;38532;Grain.Humidité;0.53;38537;Grain.Humidité;0.47;38539;Grain.Humidité;0.45;38544;Grain.Humidité;0.44;38551;Grain.Humidité;0.17 > > B;22/10/2004;38527;Partie > > aérienne.Verse;3.45;38516;Grain.Humidité;0.76;38523;Grain.Humidité;0.68;38526;Grain.Humidité;0.63;38530;Grain.Humidité;0.59;38532;Grain.Humidité;0.54;38537;Grain.Humidité;0.49;38539;Grain.Humidité;0.48;38544;Grain.Humidité;0.46;38551;Grain.Humidité;0.15 > > > > I execute the following command : > > > > reshape(tab,direction="long",varying=grep("Mesure",colnames(tab))) > > > > This gives me what I need except for a small glitch : I end up with the > > column Variable_Mesure containing the numerical values which were contained > > in the Valeur_Mesure.number columns of the wide data frame and conversely I > > have in the column Valeurs_Mesure column of my long dataframe the factor > > levels contained in the Variable_Mesure.number columns of the original wide > > dataframe. > > > > What is this "inversion" due to ? If it is an error on my part, which I > > suppose it is, how do I correct this ? > > > > Thanls in advance. > > > > PS - I am running R 2.3.1 on a Windows platform > > > > David Gouache > > Arvalis - Institut du Végétal > > Station de La Minière > > 78280 Guyancourt > > Tel: 01.30.12.96.22 / Port: 06.86.08.94.32 > > > > ______________________________________________ > > [email protected] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
