Re: [R] strange behavior of names-

2004-05-10 Thread Thomas Lumley
On Sun, 9 May 2004, Liaw, Andy wrote: Dear R-help, I've encounter what seems to me a strange problem with names-. Suppose I define the function: fun - function(x, f) { m - tapply(x, f, mean) ans - x - m[match(f, unique(f))] names(ans) - names(x) ans } which subtract

Re: [R] strange behavior of names-

2004-05-10 Thread Prof Brian Ripley
Remember tapply with a single factor in R returns a 1D array. What you are seeing are the dimnames, not the names: look at attributes() on your return value (or even name() or str() on it). I suspect you intended an as.vector() call in the formation of m. Brian On Sun, 9 May 2004, Liaw, Andy

Re: [R] strange behavior of names-

2004-05-10 Thread Peter Dalgaard
Liaw, Andy [EMAIL PROTECTED] writes: [BTW, this is using the tip that Thomas Lumley posted about forming the group means. I've wanted to write a `tsweep' function that's sort of the cross of tapply() and sweep().] Also notice that this is unsplit(lapply(split(x, g), scale, scale=FALSE), g)

[R] strange behavior of names-

2004-05-09 Thread Liaw, Andy
Dear R-help, I've encounter what seems to me a strange problem with names-. Suppose I define the function: fun - function(x, f) { m - tapply(x, f, mean) ans - x - m[match(f, unique(f))] names(ans) - names(x) ans } which subtract out the means of `x' grouped by `f' (which is the

Re: [R] strange behavior of names-

2004-05-09 Thread Gabor Grothendieck
Execute these two commands: ans - fun(x,f) attributes(ans) and you get this: $dim [1] 20 $dimnames $dimnames[[1]] [1] a a b c a d a b d d a b d c c c b c b [20] d so ans does not have names, it has dimnames. If you try dimnames(ans) - NULL then its dimnames do get nulled