[R] apply(*, 2, <NULL returning function>)

Martin Maechler maechler at stat.math.ethz.ch
Mon Oct 22 17:57:41 CEST 2001


>>>>> "Laurent" == Laurent Gautier <laurent at genome.cbs.dtu.dk> writes:

(without using Subject; PLEASE do)


    Laurent> I may have overlooked something but the following piece of
    Laurent> code causes me trouble:


    >> a_data.frame(1:4)
    >> a
    Laurent> X1.4
    Laurent> 1    1
    Laurent> 2    2
    Laurent> 3    3
    Laurent> 4    4
    >> apply(a,2,cat)
    Laurent> 1 2 3 4Error in ans[[1]] : subscript out of bounds
    >> apply(a,1,cat)
    Laurent> 1234NULL

    Laurent> Is this the fact my data.frame has only one dimension ?
    Laurent> (and do I forget somewhere (but where ?) to specify not to 'drop'
    Laurent> dimension or something similar ?)

No,
it is because  apply(*, 2, Foobar)  doesn't work when the function Foobar()
only returns NULL :

 > apply(cbind(1:4), 2, function(...)NULL)
 Error in ans[[1]] : subscript out of bounds

 > apply(data.frame(1:4), 2, function(...)NULL)
 Error in ans[[1]] : subscript out of bounds

 > apply(data.frame(1:4), 1, function(...)NULL)
 NULL

This might be considered a bug, but I don't have time to investigate
further now.


Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list