2016-06-05 13 views
-1

Ich habe das folgende Stück meines Daten-Set:Wie finde ich die Anzahl der eindeutigen Vorkommen eines Wertes im Datensatz?

> dput(test) 
structure(list(X2002.06.26 = structure(c(99L, 88L, 65L, 94L, 
60L, 101L, 27L, 83L, 16L, 12L, 54L, 97L, 63L, 41L, 13L, 2L, 58L, 
9L, 82L, 22L, 14L, 77L, 55L, 32L, 45L, 80L, 39L, 70L, 114L, 103L, 
69L, 104L, 106L, 108L, 38L, 10L, 64L, 1L, 112L, 102L, 67L, 98L, 
66L, 19L, 81L, 72L, 89L, 23L, 48L, 4L, 25L, 91L, 26L, 62L, 33L, 
3L, 28L, 57L, 17L, 20L, 73L, 78L, 90L, 84L, 5L, 92L, 43L, 74L, 
75L, 93L, 100L, 56L, 36L, 79L, 111L, 52L, 24L, 105L, 29L, 53L, 
110L, 71L, 18L, 8L, 34L, 50L, 109L, 61L, 35L, 21L, 11L, 47L, 
59L, 51L, 113L, 44L, 30L, 42L, 107L, 7L, 87L, 6L, 68L, 96L, 86L, 
15L, 46L, 85L, 31L, 49L, 40L, 76L, 95L, 115L, 37L), .Label = c("BMG4388N1065", 
"BMG812761002", "GB00BYMT0J19", "IE00BLS09M33", "IE00BQRQXQ92", 
"US0003611052", "US0015471081", "US0025671050", "US0028962076", 
"US0044981019", "US0116591092", "US01741R1023", "US0185223007", 
"US01988P1084", "US0305061097", "US0311001004", "US03662Q1058", 
"US0375981091", "US0383361039", "US03836W1036", "US03937C1053", 
"US0396701049", "US0462241011", "US06652V2088", "US0997241064", 
"US1033041013", "US1096961040", "US1170431092", "US1250711009", 
"US1258961002", "US12686C1099", "US1311931042", "US1416651099", 
"US1423391002", "US1431301027", "US1564311082", "US1718711062", 
"US1778351056", "US2193501051", "US2289031005", "US23331A1097", 
"US2537981027", "US2829141009", "US2925621052", "US2966891028", 
"US3116421021", "US34354P1057", "US3498531017", "US3693851095", 
"US3984331021", "US3989051095", "US4158641070", "US4222451001", 
"US4285671016", "US4586653044", "US4835481031", "US5261071071", 
"US5367971034", "US5463471053", "US55305B1017", "US5535301064", 
"US5562691080", "US5663301068", "US5871181005", "US59001A1025", 
"US6081901042", "US62914B1008", "US6517185046", "US6900701078", 
"US6907684038", "US6936561009", "US7081601061", "US7132781094", 
"US7234561097", "US7310681025", "US7415034039", "US7496851038", 
"US7549071030", "US7595091023", "US76009N1000", "US7703231032", 
"US7811821005", "US7835491082", "US8081941044", "US8308791024", 
"US83088M1027", "US83545G1022", "US8354951027", "US8528572006", 
"US8545021011", "US85590A4013", "US8581191009", "US8589121081", 
"US8681571084", "US8685361037", "US8712371033", "US8793691069", 
"US8799391060", "US8832031012", "US8851601018", "US8865471085", 
"US8873891043", "US88830M1027", "US8968181011", "US89785X1019", 
"US8990355054", "US90385D1072", "US9134831034", "US9202531011", 
"US92552R4065", "US9410531001", "US9427491025", "US9433151019", 
"US9633201069", "US9837721045"), class = "factor"), X2002.06.27 = structure(c(57L, 
43L, 73L, 70L, 35L, 114L, 58L, 88L, 55L, 7L, 72L, 28L, 16L, 84L, 
110L, 44L, 75L, 20L, 99L, 18L, 10L, 80L, 113L, 52L, 66L, 36L, 
60L, 101L, 107L, 103L, 34L, 22L, 81L, 40L, 1L, 46L, 108L, 106L, 
91L, 37L, 98L, 9L, 104L, 115L, 54L, 100L, 42L, 2L, 3L, 26L, 21L, 
71L, 23L, 62L, 50L, 97L, 11L, 94L, 27L, 53L, 79L, 4L, 51L, 76L, 
49L, 78L, 87L, 32L, 59L, 96L, 13L, 86L, 15L, 48L, 109L, 29L, 
85L, 68L, 17L, 41L, 64L, 31L, 8L, 38L, 90L, 45L, 12L, 56L, 6L, 
39L, 92L, 63L, 5L, 82L, 19L, 89L, 69L, 74L, 25L, 95L, 105L, 61L, 
67L, 14L, 112L, 111L, 102L, 83L, 93L, 33L, 30L, 47L, 65L, 24L, 
77L), .Label = c("CH0044328745", "GB00BVVBC028", "LR0008862868", 
"US0003611052", "US0010841023", "US0044981019", "US0079731008", 
"US0116591092", "US0305061097", "US0311001004", "US0383361039", 
"US03937C1053", "US0462241011", "US06652V2088", "US0733021010", 
"US0952291005", "US0997241064", "US1096411004", "US1096961040", 
"US1265011056", "US12686C1099", "US1311931042", "US1431301027", 
"US1564311082", "US1628251035", "US1630721017", "US1897541041", 
"US2017231034", "US23331A1097", "US2829141009", "US2925621052", 
"US29444U7000", "US2974251009", "US3024913036", "US3138551086", 
"US34354P1057", "US3596941068", "US3693851095", "US3719011096", 
"US3825501014", "US3984331021", "US3989051095", "US4108671052", 
"US4130861093", "US4158641070", "US4456581077", "US4586653044", 
"US4606901001", "US48666K1097", "US5006432000", "US5053361078", 
"US5138471033", "US5179421087", "US5246601075", "US5260571048", 
"US5463471053", "US5526761086", "US5535301064", "US5663301068", 
"US5766901012", "US59001A1025", "US6117421072", "US63935N1072", 
"US6515871076", "US67066G1040", "US6795801009", "US6819191064", 
"US6900701078", "US6907684038", "US6935061076", "US6936561009", 
"US6951561090", "US7004162092", "US73179P1066", "US7376301039", 
"US7401891053", "US74762E1029", "US7496851038", "US7549071030", 
"US7757111049", "US7811821005", "US8305661055", "US8308791024", 
"US8335511049", "US83545G1022", "US8354951027", "US8358981079", 
"US8545021011", "US85590A4013", "US86732Y1091", "US8681681057", 
"US8712371033", "US87305R1095", "US8799391060", "US8851601018", 
"US88830M1027", "US8894781033", "US8962391004", "US8968181011", 
"US89785X1019", "US9022521051", "US90385D1072", "US9046772003", 
"US9111631035", "US9134831034", "US92552R4065", "US92552V1008", 
"US9258151029", "US9292361071", "US9410531001", "US9427491025", 
"US9433151019", "US9699041011", "US9746371007", "US9807451037" 
), class = "factor")), .Names = c("X2002.06.26", "X2002.06.27" 
), class = "data.frame", row.names = c(NA, -115L)) 

Die eigentlichen Daten erstreckt sich über 3000+ Spalten und gibt es etwa 1.150 eindeutige Werte.

Ich muss zählen, wie oft jeder dieser Werte im Data-Set erscheint.

+0

Hmm, 'Tisch()' ??? –

+0

Ich probierte Tabelle Ich erhalte Fehler in der Tabelle (Daten): Versuch, eine Tabelle mit> = 2^31 Elementen –

+0

'tabulate()' zu machen? 'dplyr :: zählen'? –

Antwort

3

Wir zu flach versuchen können die Elemente in dem Datenrahmen zuerst, dann die table() Methode anwenden:

tab1 <- table(do.call(c, lapply(df, as.character))) 

Eine weitere Möglichkeit ist es, den Datenrahmen zu konvertieren, um die Matrix dann anwenden table Methode:

tab2 <- table(as.matrix(df)) 

identical(tab1, tab2) 
[1] TRUE 
+3

Oder 'table (as.matrix (df))' macht das Gleiche. –

+0

Ja, danke, dass du das hinzugefügt hast. – Psidom

+0

was ist mit 'length (unique (x))'? – pbahr

Verwandte Themen