[Rd] Private: Problem with tapply/lapply and sample (PR#3286)

peter.gedeck at pharma.novartis.com peter.gedeck at pharma.novartis.com
Wed Jun 18 19:38:33 MEST 2003


Full_Name: Peter Gedeck
Version: R1.6.2 and R1.7.0
OS: Windows XP
Submission from: (NULL) (194.191.169.72)


Hello,

I marked the bug report Private, as I don't want my email address on the web
server. The problem that I found is best explained using an example.

index <- 1:6
cluster <- c(1,1,1,2,2,3)
tapply(index,cluster,sample)

gives 

$"1"
[1] 2 1 3
$"2"
[1] 4 5
$"3"
[1] 3 2 4 1 6 5

The result for 1 and 2 is correct, the last line should however be 
$"3"
[1] 6
and not return a sample containing all data. Other functions seem to work
correctly,

> tapply(index,cluster,min)
1 2 3 
1 4 6 
> tapply(index,cluster,max)
1 2 3 
3 5 6 
>  tapply(index,cluster,sum)
1 2 3 
6 9 6 

Another example which maybe gives an indication where the problem lies is 

> index <- 1:3
> cluster <- c(1,2,3)
> tapply(index,cluster,sample)
$"1"
[1] 1
$"2"
[1] 2 1
$"3"
[1] 1 3 2

The results should be 1, 2 and 3.

I tried to identify where the error occurs, but I think the error happens in
.Internal(lapply(X,FUN)) in lapply.

Regards,

Peter



More information about the R-devel mailing list