の数の割合として報告しているだろう:与えられたテキストにその頻度をカウントし、特定の文字列を検索し、Rで関数を記述しようとする言葉
1)各観測の文字列変数に目を通す
2)ユーザが定義した特定の文字列を特定してカウントする。
3)結果が、各観測に含まれる単語の総数の割合として報告する。この機能
df <- data.frame(essay1=c("OMG. american sign language. knee-slides in leather pants", "my face looks totally different every time. lol."),
essay2=c("cheez-its and dried cranberries. sparkling apple juice is pretty\ndamned coooooool too.<br />\nas for music, movies and books: the great american authors, mostly\nfrom the canon, fitzgerald, vonnegut, hemmingway, hawthorne, etc.\nthen of course the europeans, dostoyevski, joyce, the romantics,\netc. also, one of the best books i have read is all quiet on the\nwestern front. OMG. I really love that. lol", "at i should have for dinner\nand when; some random math puzzle, which I loooooove; what it means to be alive; if\nthe meaning of life exists in the first place; how the [email protected]#$ can the\npolitical mess be fixed; how the %^&* can the education system\nbe fixed; my current game design project; my current writing Lol"),
essay3=c("Lol. I enjoy life and then no so sure what else to say", "how about no?"))
私は得ることができたfurtherestされています:これは、与えられた値は「エッセイ」の中にあるかどうかを検出するために、ユーザーを可能
find.query <- function(char.vector, query){
which.has.query <- grep(query, char.vector, ignore.case = TRUE)
length(which.has.query) != 0
}
profile.has.query <- function(data.frame, query){
query <- tolower(query)
has.query <- apply(data.frame, 1, find.query, query=query)
return(has.query)
}
ここ
は、サンプルデータセットの与えられたものの、上で概説した3つの目標のためには十分ではありません。この機能が理想的に行うことは、特定された単語の数を数え、その総数を全体のエッセイ(各ユーザーの行の合計)で除算することです。これにアプローチする方法についてのアドバイスはありますか?この記事のようにstringiパッケージを使用して
ご質問ご入力data.frameを確認してください、あなたはおそらく」didnのそれはエラーを与えるので、いくつかの引用符をエスケープする... – digEmAll
はい、私の悪い!今働いているはずです。 – Cauchy