2017-09-24 1 views
2

テキストファイルをRにアップロードすると、テキストが切り詰められてしまい、正確なカウントが得られません。テキストファイル全体が読み込まれるように、別のコマンドを使用する必要がありますか?RのテキストファイルRのすべてのテキストをロードしていません

あなたが最初にあなただけのどこにでもそれを保存し、その後、不適切な形で str_countを呼び出さずにテキストで読んでいるので、それだけの文字数を返しますR.現在における実際のオブジェクトにテキストを割り当てる必要
library(stringr) 
> readr::read_file("Apple_Wikipedia.txt") 
[1] "Apple Inc. is an American multinational technology company headquartered in Cupertino, California that designs, develops, and sells consumer electronics, computer software, and online services. The company's hardware products include the iPhone smartphone, the iPad tablet computer, the Mac personal computer, the iPod portable media player, the Apple Watch smartwatch, the Apple TV digital media player, and the HomePod smart speaker. Apple's consumer software includes the macOS and iOS operating systems, the iTunes media player, the Safari web browser, and the iLife and iWork creativity and productivity suites. Its online services include the iTunes Store, the iOS App Store and Mac App Store, Apple Music, and iCloud.\r\nApple was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in April 1976 to develop and sell personal computers. It was incorporated as Apple Computer, Inc. in January 1977, and sales of its computers saw significant momentum and revenue growth for the company.... <truncated> 
> x <- c("Apple","ios", "iphone") 
> str_count(x) 
[1] 5 3 6 

答えて

1

「Apple」(5)、「ios」(3)、「iphone」(6)。 Rコンソールのテキストの表示は、ある時点で切り捨てられますが、データは完全に保存されます。次は動作するはずです。

library(stringr)  
    apple_wiki <- readr::read_file("Apple_Wikipedia.txt") 
    x <- c("Apple","iOS", "iPhone") 
    str_count(apple_wiki, x) 

もstr_countは大文字と小文字が区別されることに注意してください、そうウィキエントリをあなたの条件に一致するか、それを回避するために、正規表現またはテキスト変換を使用するように注意してください。

関連する問題