You could think of sapply and lapply as a for-loop that operates on seq_along(NOSJ) as an index vector.
for( i in seq_along(NOSJ) NOSJ[[i]] .... then use "[[" with the 3rd argument
So the first and second results would be:
> NOSJ[[1]][[1]]
$a
[1] 1
$b
[1] 1
> NOSJ[[2]][[1]]
$a
[1] 1
$b
[1] 1
The difference between sapply
and lapply
is that sapply
attempts to use simply2array
to return a matrix or array if the dimensions of the returned values are all the same (as they are in this case when using 1
, 3
or 5
as the 3rd argument. Quite honestly I do not know why using 2,4,or 6 as the third argument does not return an atomic vector. I thought it should.