2017-09-24 3 views
2

텍스트 파일을 R에 업로드하면 텍스트가 잘리고 나옵니다. 정확한 수를 얻을 수 없습니다. 내가 사용해야만하는 또 다른 명령이 있습니까? 그래서 전체 텍스트 파일을 읽습니다.R에있는 텍스트 파일이 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

그냥 문자의 수를 반환 그래서 먼저, 현재 그냥 어디서나 저장하고 부적절한 방식으로 str_count를 호출하지 않고 텍스트로 읽는 R.의 실제 개체에 텍스트를 지정해야합니다 '애플'(5), '아이오스'(3), '아이폰'(6). R 콘솔의 텍스트 표시는 어느 시점에서 잘리지 만 데이터는 완전히 저장됩니다. 다음은 작동해야합니다.

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

도 str_count는 대소 문자를 구분 알고, 그래서 위키 항목으로 용어와 일치하거나 해결하기 위해 정규 표현식 또는 텍스트 변환을 사용하는 것이주의하십시오.