In javascript, I am used to using the map function at this point. The callback for the map function takes two (really, three) arguments: the value and the index, like so:
someArray.map((value, index) => { // do stuff })
I'm new to R, but have noticed that the apply
method is similar in that you provide some sort of data structure and then a function to run on each data element.
However, I haven't seen in the docs anywhere where I can let that function be aware of the index. Something like:
lapply(some_list, function(val, idx) print(idx))
which I would hope to output:
1
2
.
.
.
n - length of list
Am I missing something, or is this not possible in R?