Incorrect input error when trying to load CSV

Asked 2 years ago, Updated 2 years ago, 105 views

read.csv("filename", header=T, fileEncoding="utf-8")

When I tried to read in the , I found that

[1]X.
 <0 lines> (or row.names with length 0) 
 Warning message: 
in 1:read.table(file=file, header=header, sep=sep, quote=quote, and so on: 
   Invalid input in input connection 'mal.csv' 
in 2:read.table(file=file, header=header, sep=sep, quote=quote, and so on: 
  incomplete final line found by readTableHeader on 'mal.csv'

An error similar to the one shown in

appears.

Data is

area walk old cost
27.2    13  31  5.6
29.7    14  30  6.3
50.2    5   13  9
43  19  10  9.2
37.2    6   9   9.5
46.3    13  8   9.8
39.5    10  12  10
51.8    2   15  11
54.7    2   15  11.3
62.6    2   15  12.5
53.5    8   8   13.1

Yes. (I copied the above from Excel, but it was saved in csv format, so it's separated.)

Could you tell me what the problem is and how to solve it?

r csv

2022-09-30 21:23

1 Answers

Because the error message says incomplete final line found by..., the last line of mal.csv may not have a new line (no new line code at the end of the file).

Also, it looks like it's tab-separated, not comma-separated.It seems to be separated not only by tabs but also by spaces, so read.table("mal.csv", header=T,...) should be used, but the delimiter of the header part (area.walk.old.cost) appears to be ..Please check it once.

-- metropolis's Comment 1, From 2


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.