Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我在 R 中解析网站时,(系统:R+debian)控制台中的 html 对象输出让我感到不舒服。
线与线之间的差距很大。我怎样才能使它正常,缩小线条之间的差距?
也许您可以使用以下代码看到相同的输出。
options(encoding="gbk") library(XML) baseURL <- "http://www.jb51.net/article/27174.htm" txt <- readLines(baseURL) txt
有趣的是,似乎当print-ing 一个向量时,最长的元素决定了所有元素的间距。
print
你最长的字符串是txt[374]:在我的屏幕上,它需要 19 行;这意味着 的每个元素都txt将使用 19 行打印,可能会有很多空白。
txt[374]
txt
打印列表时您没有这个问题,因此解决方案是:
print(as.list(txt))
尝试用gsub()什么来代替空间。
gsub()