[R] reshape question
GOUACHE David
D.GOUACHE at arvalisinstitutduvegetal.fr
Thu May 3 18:20:37 CEST 2007
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
More information about the R-help
mailing list