tm_map
を使ってみました。それは次のエラーを出しました。どうすればこの問題を回避できますか?tm_map(...、tolower)でテキストを小文字に変換する際のエラー
require(tm)
byword<-tm_map(byword, tolower)
Error in UseMethod("tm_map", x) :
no applicable method for 'tm_map' applied to an object of class "character"
tm_map
を使ってみました。それは次のエラーを出しました。どうすればこの問題を回避できますか?tm_map(...、tolower)でテキストを小文字に変換する際のエラー
require(tm)
byword<-tm_map(byword, tolower)
Error in UseMethod("tm_map", x) :
no applicable method for 'tm_map' applied to an object of class "character"
ベースR機能tolower()
使用します。この方法でTOLOWERを使用して
tolower(c("THE quick BROWN fox"))
# [1] "the quick brown fox"
ありがとう。しかし、なぜ私はそのエラーを持っているかについての任意の洞察?他のtm_mapアプリケーションを使う必要があるかもしれません! – jackStinger
'tm_map'のヘルプファイル(' tm'パッケージ内)は利用可能な変換関数のリストを示し、 'tolower'はそれらのうちの一つではありません。変換は、クラス 'コーパス'のオブジェクトで動作するS3メソッドであるように見えます。だから、 'tm_map'を使って関数を使うことはできません。 – bdemarest
myCorpus <- Corpus(VectorSource(byword))
myCorpus <- tm_map(myCorpus , tolower)
print(myCorpus[[1]])
を望ましくない副作用を持っている:あなたは後でコーパスのうち、長期文書行列を作成しようとした場合、それは失敗するでしょう。これは、tolowerの戻り値の型を処理できないtmの最近の変更が原因です。代わりに、使用:
myCorpus <- tm_map(myCorpus, PlainTextDocument)
は、ここではより詳細な回答に私のcommentを展開する:あなたはVCorpus
オブジェクトを台無しにしないcontent_transformer
の内側tolower
をラップする必要がある - のようなもの:
> library(tm)
> data('crude')
> crude[[1]]$content
[1] "Diamond Shamrock Corp said that\neffective today it had cut its contract prices for crude oil by\n1.50 dlrs a barrel.\n The reduction brings its posted price for West Texas\nIntermediate to 16.00 dlrs a barrel, the copany said.\n \"The price reduction today was made in the light of falling\noil product prices and a weak crude oil market,\" a company\nspokeswoman said.\n Diamond is the latest in a line of U.S. oil companies that\nhave cut its contract, or posted, prices over the last two days\nciting weak oil markets.\n Reuter"
> tm_map(crude, content_transformer(tolower))[[1]]$content
[1] "diamond shamrock corp said that\neffective today it had cut its contract prices for crude oil by\n1.50 dlrs a barrel.\n the reduction brings its posted price for west texas\nintermediate to 16.00 dlrs a barrel, the copany said.\n \"the price reduction today was made in the light of falling\noil product prices and a weak crude oil market,\" a company\nspokeswoman said.\n diamond is the latest in a line of u.s. oil companies that\nhave cut its contract, or posted, prices over the last two days\nciting weak oil markets.\n reuter"
は何のパッケージです'tm_map'から?これは、いくつかの非ベースパッケージに依存しているようです。完全性のために 'library'ステートメントを含めることを検討してください。 –
@DanielKrizian: 'tm_map()'は 'tm'パッケージからのもので、' tolower() 'は' base'からのものです – smci