r - 使用 UTF-8 编码将 csv 文件导入 R 数据帧
问题描述
我正在尝试使用数据框导入 csv 文件:
pc2020 <- read.table("pc2020.csv", sep = ";", header = TRUE)
这工作正常,但编码是错误的,因此,我把所有的重音字符都搞砸了。
所以,我正在尝试:
pc2020 <- read.table("pc2020.csv", sep = ";", header = TRUE, fileEncoding = "UTF-8")
返回:
Error in read.table("pc2020.csv", sep = ";", header = TRUE, fileEncoding = "UTF-8") :
no lines available in input
In addition: Warning message:
In read.table("pc2020.csv", sep = ";", header = TRUE, fileEncoding = "UTF-8") :
invalid input found on input connection 'pc2020.csv'
解决方案
您可以使用read.csv()
具有与 . 相同的属性的函数read.table
。除了fileEncoding
- 在read.csv()
你应该写只是encoding = "UTF-8"
。
鸭子的答案也很合适。
推荐阅读
- ansible - 如何使用随机 6 位密码创建用户记录并使用 Ansible playbook 将密码设置保存在文件中
- c# - 为什么我的 C# 端点不理解我的 Angular Reactive 表单数据?
- typescript - 有没有办法在泛型参数中使用条件“类型保护”类型?
- sqlalchemy - Python Mock Patch 两个相似的函数
- javascript - 摆脱 ReactJS 的重复代码
- c# - 如何将值设置为只读 Httpcontex.request.HttpMethod?
- r - 将 eval(parse()) 应用于 r 中列的所有行
- python - 如何使用 groupby 为 Dataframe 中的每个组创建重复索引?
- python - 如何对图像的所有像素值求和 100?
- javascript - 打开文件时运行的脚本/插件 - 与代码