2
我有一個我想用lapply的數據框。我選擇了第一列在這裏的第一個值:關於tm語料庫函數的lapply行爲
link <- c(
"http://www.r-statistics.com/tag/hadley-wickham/",
"http://had.co.nz/",
"http://vita.had.co.nz/articles.html",
"http://blog.revolutionanalytics.com/2010/09/the-r-files-hadley-wickham.html",
"http://www.analyticstory.com/hadley-wickham/"
)
以獲取鏈接,並將其存儲的內容轉換成文集[感謝適用於agstudy]
create.corpus <- function(url.name){
doc=htmlParse(link)
parag=xpathSApply(doc,'//p',xmlValue)
cc=Corpus(VectorSource(parag))
meta(cc,type='corpus','link')=link
return(cc)
}
的功能,但我不能讓通過lapply工作的功能:
cc=lapply(link,create.corpus) # does not work
cc=lapply(link,nchar) # works
link=link[1] # try on single element
cc=create.corpus(link) # works
爲什麼這個函數在lapply中不起作用?
的感謝!有用。 – Henk