2016-06-09 27 views
0

Ich habe eine Liste namens res, die 83 Listen mit dem folgenden Format enthält. Ich muss eine dünne Matrix aus diesen Listen generieren. und Columns sind Indecies für die Zeile und Spalte der Sparse-Matrix und Freq ist der Eintrag für den entsprechenden Index.Erstellen einer Sparse-Matrix aus einer Liste von Listen- R

Beispiel Format für res [82] und res [83]:

[[82]] 
    Row Columns Freq 
2 82  33 1 
3 82  173 1 
4 82  211 1 
5 82  247 2 
6 82  480 2 
7 82  541 1 
8 82  974 1 
9 82 1197 1 
10 82 1416 1 
11 82 1531 1 
12 82 1797 7 
13 82 2416 2 
14 82 2530 1 
15 82 2772 1 
16 82 2970 2 
17 82 3264 4 
18 82 3416 1 
19 82 3995 4 
20 82 5593 1 
21 82 6557 1 
22 82 8141 1 
23 82 9044 1 
24 82 11889 1 
25 82 12608 1 
26 82 13352 1 
27 82 13463 1 
28 82 17937 1 
29 82 29730 1 
30 82 37712 1 
31 82 258434 1 

[[83]] 
    Row Columns Freq 
2 83  309 1 
3 83  447 1 
4 83  480 2 
5 83  487 1 
6 83  619 1 
7 83  651 1 
8 83  913 1 
9 83 1555 1 
10 83 1874 1 
11 83 2416 1 
12 83 3101 1 
13 83 3856 1 
14 83 3964 1 
15 83 3995 1 
16 83 4017 1 
17 83 4362 1 
18 83 10551 1 
19 83 17130 1 
20 83 29730 1 

Antwort

1

Wir sparseMatrix von Matrix nach rbind ing die list Elemente verwenden können.

library(Matrix) 
d1 <- do.call(rbind, lst) 
res <- sparseMatrix(d1[,1], d1[,2], x = d1[,3]) 
Verwandte Themen