[R] strange behaviour of certain fields in data frame after rbind
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu May 8 14:09:21 CEST 2003
>From the NEWS for 1.7.0:
o The data.frame method for rbind() was
- converting character columns to factors,
- converting ordered factor columns to unordered factors,
- failing to append correctly a factor to a character column
and vice versa.
and my guess is that is what you are seeing. But we can't tell the
classes of your columns from the printout. It would have been helpful to
ask yourself (and tell us) what is special about `certain fields'.
I believe this works properly in 1.6.2 if the fields are either factor or
character and protected by I() (and hence of class "AsIs").
On Thu, 8 May 2003, Joris DeWolf wrote:
> Can anybody explain me what is going wrong with the rbind command or how
> I could avoid the problem?
> I have a script with loops which time has a dataframe as output (called
> T2sbdata). After each loop I would like to append that dataframe to the
> results I obtained from the previous loops (called T2sbdataALL) and use
> for that purpose rbind.
>
> Below a part of the loop and the result I get. The rbind command does it
> job as I would expect, but cannot append the column PTGEvent properly.
>
> I use R Version 1.6.2 under Linux.
>
> Thanks
>
> Joris
>
> print("how original data look like")
> print(T2sbdataALL[1:8])
> print("how data to be appended look like")
> print(T2sbdata[1:8])
> T2sbdataALL <- rbind(T2sbdataALL,T2sbdata)
> print("How all data look after rbind")
> print(T2sbdataALL[1:8])
>
>
>
>
> [1] "how original data look like"
> IDSSB IDSeed CDnr PTGEvent ExpNr IDExp WPSNumber
> TypeExp
> 35 12102 150008 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 36 12103 150328 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 37 12104 150307 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 38 12105 150327 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 39 12106 150304 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 40 12107 149693 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 41 12108 150303 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 42 12109 149698 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 43 12110 150320 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 44 12111 150301 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 45 12112 150034 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> [1] "how data to be appended look like"
> IDSSB IDSeed CDnr PTGEvent ExpNr IDExp WPSNumber
> TypeExp
> 46 12113 150335 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 47 12114 150032 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 48 12115 150293 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 49 12116 150599 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 50 12117 150332 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 51 12118 150287 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 52 12119 150595 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 53 12120 150038 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 54 12121 150286 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> 55 12122 150333 CD3629 OS0934-09A E0.000.003.205 3116 YD03_17b
> Confirmation
> [1] "How all data look after rbind"
> IDSSB IDSeed CDnr PTGEvent ExpNr IDExp WPSNumber
> TypeExp
> 35 12102 150008 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 36 12103 150328 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 37 12104 150307 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 38 12105 150327 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 39 12106 150304 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 40 12107 149693 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 41 12108 150303 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 42 12109 149698 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 43 12110 150320 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 44 12111 150301 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 45 12112 150034 CD3629 OS0934-07A E0.000.003.205 3116 YD03_17b
> Confirmation
> 46 12113 150335 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 47 12114 150032 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 48 12115 150293 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 49 12116 150599 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 50 12117 150332 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 51 12118 150287 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 52 12119 150595 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 53 12120 150038 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 54 12121 150286 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
> 55 12122 150333 CD3629 <NA> E0.000.003.205 3116 YD03_17b
> Confirmation
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list