不需要的字符 "````导入文本文件时出现
我有一个名为 inflation.txt
的记事本 txt 文件.
I have a notepad txt file called inflation.txt
.
该文件有两列(用空格"分隔),看起来像这样:
The file has two columns (delimited with a "space") and looks something like this:
1950-1 0.0084490544865279
1950-2 −0.0050487986543660
1950-3 0.0038461526886055
1950-4 0.0214293914558992
1951-1 0.0232839389540449
1951-2 0.0299121323429455
1951-3 0.0379293285389640
1951-4 0.0212773984472849
我正在尝试将此文件导入 R.
I am trying to import this file into R.
在此处阅读之前的 stackoverflow 帖子 阅读文本在 R 中以多个空格作为分隔符的文件,我针对我的问题修改了代码
Reading this previous stackoverflow post over here Reading text file with multiple space as delimiter in R , I adapted the code for my problem
data <- read.table("inflation.txt", sep = "" , header = F ,
na.strings ="", stringsAsFactors= F)
但是当我运行上面的代码时,出现了一个不需要的字符(-"):
But when I run the above code, an unwanted character appears ( " −") :
> head(data)
V1 V2
1 1950-1 0.0084490544865279
2 1950-2 −0.0050487986543660
3 1950-3 0.0038461526886055
4 1950-4 0.0214293914558992
5 1951-1 0.0232839389540449
6 1951-2 0.0299121323429455
有人可以告诉我我做错了什么吗?数据是否损坏?有没有办法解决这个问题?
Can someone please show me what I am doing wrong? Is the data getting corrupted? Is there a way to fix this problem?
如果你试试这个,你会得到什么
What do you get if you try this
data <- read.table("inflation.txt", sep = "" , header = F ,
na.strings ="", stringsAsFactors= F, encoding = "UTF-8")
那个奇怪的字符看起来像一个 utf-8 符号
That weird character looks like a utf-8 symbol