48

を使ってみましたtm_map。次のエラーが発生しました。どうすればこれを回避できますか?

 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"
4

4 に答える 4

102

ベース R 関数を使用しますtolower()

tolower(c("THE quick BROWN fox"))
# [1] "the quick brown fox"
于 2012-11-30T06:41:32.717 に答える
6

ここで私のコメントをより詳細な回答に拡張します。オブジェクトを台無しにしないように、tolower内部でラップする必要があります-次のようなものです:content_transformerVCorpus

> 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"
于 2016-07-20T08:07:13.860 に答える
3
myCorpus <- Corpus(VectorSource(byword))
myCorpus <- tm_map(myCorpus , tolower)

print(myCorpus[[1]])
于 2013-07-25T17:10:31.737 に答える
1

この方法で tolower を使用すると、望ましくない副作用があります。後でコーパスから用語ドキュメント マトリックスを作成しようとすると、失敗します。これは、 tolower の戻り型を処理できない tm の最近の変更によるものです。代わりに、次を使用します。

myCorpus <- tm_map(myCorpus, PlainTextDocument)
于 2015-06-25T19:48:43.703 に答える