I\'m slightly confused as to whether lapply works on a list or on a vector. See two examples below
Here, the mean function is applied over an array of numbers,
lapply
will work on whatever is the highest level which defines the structure of the R object.
If I have 4 individual integers, lapply
will work on each integer:
x <- 1:4
lapply(x, identity)
#[[1]]
#[1] 1
#
#[[2]]
#[1] 2
#
#[[3]]
#[1] 3
#
#[[4]]
#[1] 4
If however I have a list
of length==2 each containing 2 values, lapply
will work on each list object.
x <- list(1:2,3:4)
lapply(x, identity)
#[[1]]
#[1] 1 2
#
#[[2]]
#[1] 3 4