Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Elegant, functional way to extract data from this nested R list

$
0
0

Given the following configuration object:

sourceClust = list(
  clust1 = list(
    prop = 0.25,
    Dim1 = list(
      mean = 2,
      sd   = 0.05
    ) ,
    Dim2 = list(
     mean = 3,
     sd = .1
    )
  ),
  clust2 = list(
    Dim1 = list(
      mean = 4,
      sd   = .1
    ),
    Dim2 = list(
      mean = 3,
      sd = 0.2
    ),
    prop = 0.75
  )
);

Is there an elegant, functional way to extract the data in the following format?

clusterMeans = data.frame(Dim1=c(2,4),Dim2=c(3,3));
clusterSD = data.frame(Dim1 = c(0.05,0.1), Dim2 = c(0.1,0.2));
clusterProp = c(0.25, 0.75);

I understand that the above can be accomplished with some nested loops, but I'm trying to see if I can use functional styling to accomplish this task. I'm looking for a solution in base R or using a library (tidyverse is great).


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>