如何在R中读取'utf-8'文本文件? [英] How can I read 'utf-8' text file in R?

查看:251
本文介绍了如何在R中读取'utf-8'文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 R 中阅读文本文件。

I need to read text file in R.

所以我使用 read.delim()。

当我阅读编码的文本文件 ASCII

It works well when I read text file encoded ASCII

时,效果很好,但是我看不到 UTF-8

but I can't read UTF-8

所以我必须将文本文件编码为 ASCII

so I have to encode the text file to ASCII

如何在R中将文本文件编码为ASCII?

how can I encode text files to "ASCII" in R?

当我阅读 utf-8 文本文件时,下面的警告消息。

the warning message below present when I read utf-8 text file.

似乎文件路径isn' t阅读

It seems file path isn't read

警告信息:

1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  invalid input found on input connection 'C:/?곗씠?곕텇??OB留μ</02.INPUT_DB_query_data/POC?곗씠??DRAFT/DRAFT_20110105.txt'
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'C:/?곗씠?곕텇??OB留μ</02.INPUT_DB_query_data/POC?곗씠??DRAFT/DRAFT_20110105.txt'
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  header and 'col.names' are of different lengths


推荐答案

尝试使用 encoding ='UTF-8'

read.delim(file='filename',
           encoding='UTF-8'
           #Other settings
           )

我希望这将工作....

I hope this will work....

这篇关于如何在R中读取'utf-8'文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆