这个问题的组织:
I. Background
II. The Problem/Question
III. Steps Taken to Make this Question Good
IV. Update: the output of head(x.path) and dput(x.path)
Run Code Online (Sandbox Code Playgroud)
一,背景
我正在定制/调整O'Reilly的书"黑客机器学习"(第3章)中的电子邮件分类代码.该代码及其附带数据可在此处找到:https://github.com/johnmyleswhite/ML_for_Hackers/tree/master/03-Classification
II.问题/问题
调用该代码中的一个主要功能get.msg().原来的功能是
get.msg <- function(path)
{
con <- file(path, open = "rt", encoding = "latin1")
text <- readLines(con)
# The message always begins after the first full line break
msg <- text[seq(which(text == "")[1] + 1, length(text), 1)]
close(con)
return(paste(msg, collapse = "\n"))
}
Run Code Online (Sandbox Code Playgroud)
我的数据在很多方面都有所不同,所以我必须对此进行相当多的编辑.我之前从关系数据库中读取了我的数据,因此我不必读入并清理文本文件.相反,我的电子邮件正文数据是数据框的第18列,我们可以调用它x.这是我的版本get.msg():
get.msg <- …Run Code Online (Sandbox Code Playgroud)