[R] Change of parsing parameters to functions between 0.63.1and 0.63.3 ?

Athula Herath Athula.Herath at ogs.co.uk
Wed Mar 24 21:41:11 CET 1999


Many thanks for Prof Ripley and also Peter Dalgaard  for offering help
in this issue. I have
now changed the code to do the right thing. The function has been
changed to:


cave<-function(x,a,b,bb)
{
    names(x)<-bb
    cat("x[a]->",x[a],"x[b]->",x[b],"\n")
 
    return(c(mean(x[a],na.rm=T),mean(x[b],na.rm=T)))
}
datx <- data.frame(rbind(c(1,2,3,4),c(4,5,6,7)))
names(datx)<-c("A","B","C","D")
f1<-c("A","C")
f2<-c("B","D")
t1<-apply(datx,1,cave,f1,f2,names(datx))

It works fine.

Thanks again for your kind help.


Athula./




Prof Brian D Ripley wrote:
> 
> On Wed, 24 Mar 1999, Athula Herath wrote:
> 
> >> 
> The help page for apply says
> 
> Arguments:
> 
>        x: the array to be used.
> 
> and your x is not an array, although R does an as.matrix for you. The
> problem is that you are expecting apply to hand you a row vector labelled
> by the column names of the (coerced) matrix. This is true in some versions
> of R but not in others, and AFAIK is not documented to be expected. The
> names of a vector are attributes, and we have been debating which
> attributes should be retained on subsetting (as here).
> 
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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