[R] (no subject)

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Sat Nov 4 01:29:06 CET 2006


On 03-Nov-06 Martin Maechler wrote:
> [...]
> But I want to make another point:
> 
> For about a year now, for "serious" data-analysis using
> data frames, I've been advocating to use the slightly more
> clumsy but much more error-prone ``column indexing by name''
> instead of the quick-and-dirty "$" selection :
> 
>   > x$bar
>   NULL
> 
>   > x[,"bar"]
>   Error in "[.data.frame"(x, , "bar") : undefined columns selected

Your point is well made, Martin, but I'd like to present a
different view of the same issue.

Suppose you are working on a somewhat flexibly structured
computation in which columns get adjoined to a dataframe
(by name) according (e.g.) as they become available at
some (unforeseeable) point in the pathway through the
computation. This could also arise in "real time" if "bar"
is the output from some measuring device, not yet available,
yet the computation can get on with other things until it
is available.

Then a test based on

  is.null(x$bar)

could divert the computation round some path suitable for
a case where x$bar has not yet been defined and adjoined,
as opposed to a case where x$bar has already been adjoined.

The use of x[,"bar"], however, would generate an error and
cause the computation to slide through a hole in the floor.

"Horses for courses", I suppose!

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 04-Nov-06                                       Time: 00:29:03
------------------------------ XFMail ------------------------------



More information about the R-help mailing list