[英]How to read non-english characters with read.delim in R?
我有一個包含多種語言的文本文件,如何在 R 中使用read.delim
函數讀取,
Encoding("file.tsv")
#[1] "unknown"
source_data = read.delim(file, header= F, fileEncoding= "windows-1252",
sep = "\t", quote = "")
source_D[360]
#[1] "ð¿ð¾ð¸ñðº ð½ð° ññ‚ð¾ð¼ ñð°ð¹ñ‚ðµ"
但是記事本中顯示的source_D[360]
是'поиск на этом сайте'
tidyverse 方法:
在 read_delim 中使用選項locale
。 (readr 函數有 _ 而不是 . 並且通常更快更聰明地閱讀)更多細節在這里: https ://r4ds.had.co.nz/data-import.html#parsing-a-vector
source_data = read_delim(file, header= F,
locale = locale(encoding = "windows-1252"),
sep = "\t", quote = "")
source_data = read.delim(file, header = F, sep = "\t", quote = "", stringsAsFactors = FALSE)
Encoding(source_data)= "UTF-8"
我試過,如果你在 Windows 中運行你的 R,上面的代碼對我有用。 如果您在 Unix 中運行 R,則可以使用以下代碼
source_data = read.delim(file, header = F, fileEncoding="UTF-8", sep = "\t", quote = "", stringsAsFactors = FALSE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.