I want to extract the names of the elements of a list on which I am applying a function within the lapply(). EDIT: perhaps this was not clear so just to clarify it has to be done in lapply().
Here is a reproducible example to clarify.
A <- c("z", "y", "x", "v")
B <- c("q", "j", "k", "r")
C <- c("n", "e", "d", "f")
myList <- list(A = A,B = B, C = C)
names_list <- lapply(myList, function(x) {
???(x)
})
output: "A" "B" "C"
I am not sure how this could be done, and I cannot find any information online. The closest I have come to the desired output is by using
get_obj_name from the envnames package but it gives me
$A
[1] "x"
$B
[1] "x"
$C
[1] "x"
Thank you for your help.