[R] Trying to get an apply to work with a list in applying names to tables
John Kane
jrkrideau at yahoo.ca
Wed Feb 21 16:47:07 CET 2007
I am trying to use apply and a list to supply names
to a set of tables I want to generate. Below is an
example that I hope mimics the larger original
problem.
EXAMPLE
aa <- c( 2,2,1,1,2)
bb <- c(5,6,6,7,4)
aan <- c("yes", "no")
bbn <- c("a", "b", "c", "d")
mynames <- c("abby", "billy")
mylist <- list(aan, bbn); names(mylist) <- mynames
cc <- data.frame(aa,bb)
fn1 <- function(x,y) {tt <- table(x); names(tt)<-
mylist[[y]]}
jj <-apply(cc, 2, fn1(cc,mylist))
RESULT:
Error in fn1(cc, mylist) : invalid subscript type
To be honest I didn't expect it to work since that
fin1(cc looks recursive but oh well...
Can anyone offer a solution or some advice here. It
would be greatly appreciated
More information about the R-help
mailing list