I have an example data that saved as csv file in this websit.
The 1.csv was sent to me by someone else and I can not read it into R correctly using read.csv.
> dat = read.csv('1.csv')
Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote, :
line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote, :
line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on 'data/hanze/1.csv'
Then I also tried adding sep in read.csv but also failed.
dat = read.csv('1.csv', sep = ',')
dat = read.csv('1.csv', sep = '\t')
Finally I re-save the 1.csv file using Microsoft Excel as a new csv file with comma separator named 1_test.csv and it works.
dat = read('1_test.csv', encoding = 'UTF-8')
head(dat)
id station lon lat RASTERVALU
1 1 东四 116.417 39.929 0.2406870
2 2 天坛 116.407 39.886 0.0992821
3 3 官园 116.339 39.929 0.1243020
4 4 万寿西宫 116.352 39.878 0.2394120
5 5 奥体中心 116.397 39.982 0.2368810
6 6 农展<e9><U+00A6>? 116.461 39.937 0.2307600
In my real situation, I have hundreds of file like 1.csv and I do not want to re-save them as a new csv file using Microsoft Excel.
My question is that is there a way that could read the 1.csv straightly and correctly into R without re-save it?