Could somebody elaborate on the situation:
1. The class data.sheet is a subclass of data.frame
2. columns of data frames MUST be the same length
3. data sheets can have columns of variable lengths
I thought that subclass should inherit class properties, and, possibly, add
the new ones. Here the subclass does not have the property of the class, is
it correct ?
I would treat this as a bug:
1. data frame must have columns of the same length
2. TEMP2 is the data.frame (is.data.frame(TEMP2) == T)
3. TEMP2 may have columns of different length
Thanks,
Leonid
At 12:10 PM 11/30/01 -0500, Bliese, Paul D MAJ WRAIR-Wash DC wrote:
>Sorry about the apparent faux-pax of attaching my data to my previous post.
>
>Thanks to those who solved my problem. In a nutshell, my first TEMP2 was a
>data.sheet, and my second TEMP2 (i.e., data.frame(TEMP2)) was a data.frame.
>Apparently, using the ifelse command on a data.sheet is something to be
>avoided.
>
>Bill Dunlap provided the most comprehensive answer (listed below), but a
>couple of other people suspected data.sheets. What I've learned is that it
>might be valuable to check the class attributes of my data.frame prior to
>using ifelse (as in >class(TEMP2)).
>
>
>Paul
>
>Bill's message follows:
>
>*****************************************
>On Thu, 29 Nov 2001, Bliese, Paul D MAJ WRAIR-Wash DC wrote:
>
>> Note that this does NOT work -- the results are incorrect. However, one
>> simple change fixes things.
>>
>> > source("g:\\temp\\temp2.dat")
>> > TEMP2<-data.frame(TEMP2) # THIS IS THE CRITICAL CHANGE!!!!!
>> > is.data.frame(TEMP2)
>> [1] T
>
>The original TEMP2 is a "data.sheet" and data.sheets may have
>columns of different lengths. The class data.sheet is a subsclass
>of data.frame so is.data.frame(TEMP2) is TRUE.
>
>> > TEMP2[,c(2:3)]<-ifelse(TEMP2[,c(2:3)]>1,1,0)
>> > apply(TEMP2[,2:3],2,summary.ordered)
>> STR01 STR02
>> 0 572 453
>> 1 560 674
>> NA's 60 65
>
>ifelse(TEMP2[,c(2:3)]>1,1,0) produces a vector whose length is
>twice the length of a column of TEMP2. Since columns of data frames
>must be the same length [<-.data.frame converts that long vector to 2
>columns,
>each having half the vector. Since data sheets can have columns
>of variable lengths [<-.data.sheet takes the input vector as is
>and makes it the value of both columns.
>
>----------------------------------------------------------------------------
>
>Bill Dunlap 22461 Mt Vernon-Big Lake Rd
>
>Insightful Corporation Mount Vernon, WA 98274
>bill@insightful.com 360-428-8146
>
>
>
>---------------------------------------------------------------------
>This message was distributed by s-news@lists.biostat.wustl.edu. To
>unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
>the BODY of the message: unsubscribe s-news
>
|