[R] data.frame objects as seen by tapply

From: Ivan Alves <papucho_at_mac.com>
Date: Thu 21 Apr 2005 - 21:32:09 EST

Dear all,

I have encountered a bizarre ocurrence: tapply() does not treat the columns of data.frame[,cols] in the same way as those of data.frame[1:length(data.frame),cols]. Whilst for the latter it identifies the "length" of the column to be length(data.frame) in the former it does not seem to. I am enclosing the code where this happens. Any clues?

asset.t <- sapply(
# asset[,sapply(asset,is.numeric),drop=T], # returns error "Error in tapply(x, frame[row, index], FUN = sum, na.rm = TRUE) : arguments must have same length"

	FUN = apply_cols,
	frame = asset,
	index = "NAME"

# Function definitions
apply_cols <- function(x, frame, row = 1:length(frame), index) tapply( x, frame[row, index], FUN=sum, na.rm=TRUE )

Ivan Alves

R-help@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 Received on Thu Apr 21 21:37:13 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:20 EST