Thanks you, I can get the length of aa with length(unlist(aa)). If aa has 4 dimensions, I imagine I'd need to do max(sapply(aa,sapply,sapply,length) How can I do this in a generic way? That is in a loop. I am clear about the exit condition for the loop. d<-1 start loop if d = length(unlist(aa)) then exit loop else     d<-d * How do I construct such that it does  > d<- d * length(aa)                      # first pass > d<- d * max(sapply(aa, length))         # second pass > d<- d * max(sapply(aa, sapply, length)) # third pass > # ? #                                    # fourth path etc (Apologies for the pseudo code describing the loop; I am not near a machine with R) One way I can thing of is to create a loop counter variable, say lc<-1 and to increment it within the loop and then use a switch statement to execute the appropriate expression. This sems like a kludge to me. Is there a neater way? [[alternative HTML version deleted]]