0

Possible Duplicate:
Access lapply index names inside FUN

I was wondering if it was possible to access the number of the object within a list when using lapply?

If I was using a for(i in 1:100){.....} function I could just use print(i) to get this, but is there any way of doing this using lapply. I know using the function substitute() I can return something list X[[6L]] if I was in the 6th object, but is there away of just returning 6?

Thanks

Community
  • 1
  • 1
user1165199
  • 6,351
  • 13
  • 44
  • 60
  • 2
    I think http://stackoverflow.com/questions/9950144/access-lapply-index-names-inside-fun answers your question – csgillespie Apr 03 '12 at 13:13
  • This may be helpful as well: http://ryouready.wordpress.com/2009/03/16/r-monitor-function-progress-with-a-progress-bar/ – Tyler Rinker Apr 03 '12 at 14:14
  • Thanks, managed to do it using the following in the end: lapply(list, function(x){ index <- as.numeric(gsub("\\D", "", substitute(x))) index <- index[!is.na(index)] } ) – user1165199 Apr 05 '12 at 13:04

0 Answers0