Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Patrick Burns
This is Circle 8.1.47 of 'The R Inferno'. http://www.burns-stat.com/documents/books/the-r-inferno/ Pat On 14/05/2013 09:52, Luca Nanetti wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I

Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Tsjerk Wassenaar
t(apply(test,1,sample)) will also do. As the OP noted, the results are simply transposed. So if an operation is to be applied to rows, yielding modified rows, simply transpose the results. Cheers, Tsjerk On Tue, May 14, 2013 at 12:07 PM, Ted Harding wrote: > On 14-May-2013 09:46:32 Duncan Murd

Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Gabor Grothendieck
On Tue, May 14, 2013 at 4:52 AM, Luca Nanetti wrote: > Dear experts, > > I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a > bug, it is per spec, but it is so counterintuitive that I thought it could > be interesting. > > I have an array, let's say "test", dim=c(7,5). > >

Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Ted Harding
On 14-May-2013 09:46:32 Duncan Murdoch wrote: > On 13-05-14 4:52 AM, Luca Nanetti wrote: >> Dear experts, >> >> I wanted to signal a peculiar, unexpected behaviour of 'apply'. >> It is not a bug, it is per spec, but it is so counterintuitive >> that I thought it could be interesting. >> >> I have a

Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Rui Barradas
Hello, The problem is that apply returns the results vector by vector and in R vectors are column vectors. This is not exclusive of apply with sample as the function to be called, but of apply in general. Try, for instance apply(test, 1, identity) # transposes the array The rows are returne

Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Enrico Schumann
On Tue, 14 May 2013, Luca Nanetti writes: > Dear experts, > > I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a > bug, it is per spec, but it is so counterintuitive that I thought it could > be interesting. > > I have an array, let's say "test", dim=c(7,5). > >> test <-

Re: [R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Duncan Murdoch
On 13-05-14 4:52 AM, Luca Nanetti wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say "test", dim=c(7,5). test <- array(1:35, dim=

[R] Unexpected behavior of "apply" when FUN=sample

2013-05-14 Thread Luca Nanetti
Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say "test", dim=c(7,5). > test <- array(1:35, dim=c(7, 5)) > test [,1] [,2] [,3] [,4]