Here's a simple basic R solution (which will return 0 instead of NA (not sure if good enough)
temp <- unlist(lstX) res <- data.frame(do.call(rbind, strsplit(names(temp), "\\.")), value = temp)
Amount
xtabs(value ~ X1 + X2, res)
Funds
xtabs(value ~ X1 + X2, res) / length(lstX)
Alternatively, a more flexible data.table solution
library(data.table) #V1.9.6+ temp <- unlist(lstX) res <- data.table(names(temp))[, tstrsplit(V1, "\\.")][, value := temp]
Amount
dcast(res, V1 ~ V2, sum, value.var = "value", fill = NA) # V1 abc # 1: A 1 2 NA # 2: B 2 1 NA # 3: C 1 1 1 # 4: D 2 1 2
Funds
dcast(res, V1 ~ V2, function(x) sum(x)/length(lstX), value.var = "value", fill = NA)
In general, you can use almost any function with dcast
source share