我列出了大約100,000次出現的項目被排列在一起,我已粘貼到一列中,因此我可以統計每個組合出現的次數。
R中列表的出現次數
4845 Curly Fries California Burger 1
4846 French Fries California Burger 1
4847 Hamburger California Burger 1
4848 $1 Fountain Drinks Curly Fries 1
4849 $1 Fountain Drinks Curly Fries 1
4850 California Burger Curly Fries 1
4851 Curly Fries Curly Fries 1
我已經探索了聚合函數使我有以下錯誤:
aggregate(t1$count,list(t1$pc), sum) <br>
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list? <br>
我也曾嘗試ddply的變化:
ddply(t1,t1$pc,transform,occurances=sum(t1$count))
但我得到這個錯誤
Error in UseMethod("as.quoted") :
no applicable method for 'as.quoted' applied to an object of class "c('matrix', 'list')"
我假設我得到這個,因爲我試圖通過一個字符值本質上「組」。我也根據對類似問題的回答探討了tapply
和recast
,但無濟於事。
我怎樣才能得到這個組合數?
的考慮,單獨列出的項目(再次,道歉的格式問題)的一個樣本:
Var1 Var2 Var3
>2 Onion Rings Onion Rings 1
>3 Pineapple Cheddar Burger Onion Rings 1
>4 Onion Rings Pineapple Cheddar Burger 1
>5 Pineapple Cheddar Burger Pineapple Cheddar Burger 1
>5 Onion Rings Onion Rings 1
>6 Pineapple Cheddar Burger Onion Rings 1
>7 Onion Rings Pineapple Cheddar Burger 1
>8 Pineapple Cheddar Burger Pineapple Cheddar Burger 1
>9 Fountain Soda Fountain Soda 1
>10 French Fries Fountain Soda 1
你可以使用'table'函數:'table(t1 $ pc)'。 – Justin 2013-02-26 19:51:36