我加载数据
read.table("path.txt", sep = "\t", header=TRUE, fileEncoding="UCS-2")
它包含三行
x x2
MAKFA МАКФА
makar макароны
макар. макароны
但我得到警告
incomplete final line found by readTableHeader on
并输出我的数据集(实际不完整)
x x2
1 MAKFA МА
如何解决此问题(我只需要使用.txt)
structure(list(x = structure(1L, .Label = "MAKFA", class = "factor"),
x2 = structure(1L, .Label = "МА", class = "factor")), .Names = c("x",
"x2"), class = "data.frame", row.names = c(NA, -1L))
解决方案在这里 'Incomplete final line' warning when trying to read a .csv file into R 不起作用
答案 0 :(得分:1)
这可能不是最佳选择,但它可以工作。 $in = [
[1,1,'data1'],
[2,1,'data2'],
[3,2,'data3'],
[4,2,'data4'],
[5,1,'data5'],
[6,3,'data6'],
];
$out = [];
foreach ($in as $arr) {
if ($arr[1] == 1) {
$out[] = $arr;
}
}
var_dump($out);
对ICU库的依赖使其成为克服编码问题的瑞士军刀。当我看到stringi
可以正确读取文件时,我决定尝试一下vim
:
stringi