I want to use R to summarize numerical data in a table with non-unique rownames to a result table with unique row-names with values summarized using a custom function. The s
Short answer: provide a value for fill as follows acast(tab.melt, gene~variable, summarize, fill=0)
Long answer: It appears your function gets wrapped as follows, before being passed to vapply in the vaggregate function (dcast calls cast which calls vaggregate which calls vapply):
fun <- function(i) {
if (length(i) == 0)
return(.default)
.fun(.value[i], ...)
}
To find out what .default should be, this code is executed
if (is.null(.default)) {
.default <- .fun(.value[0])
}
i.e. .value[0] is passed to the function. min(x) or max(x) returns Inf or -Inf on when x is numeric(0). However, max(x)/min(x) returns NaN which has class logical. So when vapply is executed
vapply(indices, fun, .default)
with the default value being is of class logical (used as template by vapply), the function fails when starting to return doubles.