我正在尝试将多个Word文档的内容导入R中的同一对象中。我正在遵循Julia Silge和David Robinson的指南(请参见此处:https://www.tidytextmining.com/usenet.html)。
我无法弄清楚导入时如何正确编码“文本”列。
这是我正在使用的代码:
# Define a function to read all files from a folder into a data frame
read_folder <- function(infolder) {
tibble(file = dir(infolder, full.names = TRUE)) %>%
mutate(text = map(file, read_lines)) %>%
transmute(id = basename(file), text) %>%
unnest(text)
}
# Use unnest() and map() to apply read_folder to each subfolder
raw_text <- tibble(folder = dir(training_folder, full.names = TRUE)) %>%
unnest(map(folder, read_folder)) %>%
transmute(newsgroup = basename(folder), id, text)
以下是结果文本列的示例:
<f7><e5><95><e3><a9>O<af><a5><fa> PK
导入数据后是否需要更改编码?