1
項目を、解析するベクトルに追加して数えて、私は映画についてのデータを分析しています。私はジャンルを解析して数えたいと思う。R:
私のデータは以下のようになります。
DATA1、DATA2、コメディ|アクション|アドベンチャー、DATA4は、私はジャンルの数をカウントしたい
をDATA5。私は、コードでアイテムを解析するために管理してきました:
genres <- as.data.frame(table(c(movies["genres"])))
# genres look like:
# Var1 Freq
# 1 Action 11
# 2 Action|Adventure 11
# 3 Action|Adventure|Animation|Comedy|Crime|Family|Fantasy 1
# ...
# as you can see there are items which I need to parse
# for 'debugging' purpose I managed to get
strsplit(toString(genres$Var1[3]), split = "|", fixed = TRUE)
# which results in below output:
# [[1]]
# [1] "Action" "Adventure" "Animation" "Comedy" "Crime" "Family" "Fantasy"
# My idea is to gather every parsed item into one object, then treated
# that object "as.data.frame" so I could use 'Freq' from data.frame
# please take a look at below code:
genres <- as.data.frame(table(c(movies["genres"])))
list <- c()
i = 1
while(i <= length(genres$Var1)){
parse <- strsplit(toString(genres$Var1[i]), split = "|", fixed = TRUE)
merge(list, parse)
i = i + 1
}
は、誰かがそれを達成するか、どのように私は簡単な方法でジャンルをカウントすることができますどのように良いアイデアを提供することができます。事前
ありがとうございました!これは私が得たかったものです –
は、実データ@Heheszekで効率的なソリューションでしたか?もしそれがあったら、答えをアップアップしてもいい?ありがとう。 http://stackoverflow.com/help/someone-answers –
ああ、私はダニが十分だったと思いました。ご協力ありがとうございました。 –