s-news
[Top] [All Lists]

Re: Answer to ifelse and data.frames

To: Leonid Gibiansky <lgibiansky@emmes.com>
Subject: Re: Answer to ifelse and data.frames
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Fri, 30 Nov 2001 17:59:22 +0000 (GMT)
Cc: "'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>
In-reply-to: <3.0.5.32.20011130123601.0091d260@netgate.emmes.com>
On Fri, 30 Nov 2001, Leonid Gibiansky wrote:

> 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

`subclass' is not AFAIK a documented concept in S, but inheritance is. And
data.sheet()  returns an object of

        oldClass(ret) <- c("data.sheet", "data.frame")

that is of a class which inherits from "data.frame" (or extends it, in
the Green Book terminology). However

> inherits("data.sheet", "data.frame")
[1] F

(6.0 on Linux).  So although generally data.sheets seem not to inherit,
its class generator generates objects which do.

As you point out, data sheets do not inherit from data frames, so this is
not a good design.  But then class glm does not inherit properly from
class lm ....

Data sheets are not one of Insightful's better design decisions!

>
> 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
> >
> ---------------------------------------------------------------------
> 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
>

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>