[Rd] tapply on empty data.frames (PR#10644)

hilmar.berger at imise.uni-leipzig.de hilmar.berger at imise.uni-leipzig.de
Sun Jan 27 23:10:04 CET 2008


Full_Name: Hilmar Berger
Version: 2.4.1/2.6.2alpha
OS: WinXP
Submission from: (NULL) (84.185.128.110)


Hi all,

If I use tapply on an empty data.frame I get an error. I'm not quite sure if one
can actually expect the function to return with a result. However, the error
message suggests that this case does not get handled well.

This happens both in R-2.4.1 and 2.6.2alpha (version 2008-01-26).

> z = data.frame(a = c(1,2,3,4),b=c("a","b","c","d"))
> z1 = subset(z,a == 5)
> tapply(z1$a,z1$b,length)
Error in ansmat[index] <- ans : 
  incompatible types (from NULL to logical) in subassignment type fix

Deleting unused factor levels from the group parameter gives:

> tapply(z1$a,factor(z1$b),length)
logical(0)


Regards,
Hilmar

platform       i386-pc-mingw32                          
arch           i386                                     
os             mingw32                                  
system         i386, mingw32                            
status         alpha                                    
major          2                                        
minor          6.2                                      
year           2008                                     
month          01                                       
day            26                                       
svn rev        44181                                    
language       R                                        
version.string R version 2.6.2 alpha (2008-01-26 r44181)



More information about the R-devel mailing list