I have a set of 94 matrices within a list in R. Each matrix is a different size; a sample is shown below:
> summary(full_matrix)
Length Class Mode
Alex_1 64 -none- numeric
Alex_10 2500 -none- numeric
Alex_11 2916 -none- numeric
Alex_12 20736 -none- numeric
Alex_13 28900 -none- numeric
Alex_14 62500 -none- numeric
Alex_15 93025 -none- numeric
Alex_2 100 -none- numeric
Alex_3 25 -none- numeric
Alex_4 1225 -none- numeric
Alex_5 2304 -none- numeric
Alex_6 1849 -none- numeric
I want to extract data from each matrix using lapply()
. I'm performing a cluster analysis on each matrix, which generates a subset of clusters for each. I can do this using the following code:
library(pvclust)
clustering_data <- lapply(full_matrix, FUN = function(element) {
result <- pvclust(element, method.dist="cor", method.hclust="average", nboot=1000, parallel=TRUE)
output <- pvpick(result, alpha=0.95, pv="au", type="geq", max.only=TRUE)
})
For clustering_data[[1]]
, for example, this gives me:
> clustering_data[[1]]
$clusters
$clusters[[1]]
[1] "bah" "hello" "huh" "ooh" "wee" "woo"
$edges
[1] 5
The problem is that I need to be able to identify the name of the original matrix (Alex_1
, Alex_2
, etc) from which the cluster is generated, and I can't figure out how to do this. I have done it for a previous lapply()
function using df %>% split(., f = .$var1)
, but I can't figure this out when the object is in a list.