[R] Surprising Behavior of 'tapply'

Carlos Ortega carlos_ortegafernandez at yahoo.es
Thu Feb 3 19:56:06 CET 2005


Hi,

That is something strange, I could not replicate it...

Regards,
Carlos.

+++++++++++++++++++++++++++++++++++
> version
         _              
platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    2              
minor    0.1            
year     2004           
month    11             
day      15             
language R              
> sex <- rep(c("F", "M"), 5)
> income <-  c(rep("low", 5), rep("high", 5))
> count <- 1:10
> mydf <- as.data.frame(cbind(sex, income, count))
> mydf$count = as.numeric(as.character(mydf$count))
> tapply(mydf$count, list(mydf$sex, mydf$income),
FUN=sum)
  high low
F   16   9
M   24   6
++++++++++++++++++++++++++++++++++++++++++++


 --- "Rau, Roland" <Rau at demogr.mpg.de> escribió: 
> Dear all,
> 
> I wanted to make a two-way-table of two variables
> with a counting
> variable stored in another column of a dataframe. In
> version 1.9.1, the
> behavior is as expected as shown in the simplified
> example code.
> 
> > sex <- rep(c("F", "M"), 5)
> > income <-  c(rep("low", 5), rep("high", 5))
> > count <- 1:10
> > mydf <- as.data.frame(cbind(sex, income, count))
> > mydf$count = as.numeric(as.character(mydf$count))
> > tapply(mydf$count, list(mydf$sex, mydf$income),
> FUN=sum)
>   high low
> F   16   9
> M   24   6
> > version
>          _              
> platform i386-pc-mingw32
> arch     i386           
> os       mingw32        
> system   i386, mingw32  
> status                  
> major    1              
> minor    9.1            
> year     2004           
> month    06             
> day      21             
> language R              
> > 
> 
> In version 2.0.1, however, I get the following
> output:
> 
> > sex <- rep(c("F", "M"), 5)
> > income <-  c(rep("low", 5), rep("high", 5))
> > count <- 1:10
> > mydf <- as.data.frame(cbind(sex, income, count))
> > mydf$count = as.numeric(as.character(mydf$count))
> > tapply(mydf$count, list(mydf$sex, mydf$income),
> FUN=sum)
> Error in get(x, envir, mode, inherits) : variable
> "FUN" was not found
> > version
>          _              
> platform i386-pc-mingw32
> arch     i386           
> os       mingw32        
> system   i386, mingw32  
> status                  
> major    2              
> minor    0.1            
> year     2004           
> month    11             
> day      15             
> language R              
> > 
> 
> Was this change in behavior intended with the
> changes in tapply from
> R1.9.1 to R2.0.1?
> Is the R-help-list appropriate or rather R-Devel?
> 
> Thanks,
> Roland
> 
> 
> 
> +++++
> This mail has been sent through the MPI for
> Demographic Rese...{{dropped}}
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list