Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
786 views
in Technique[技术] by (71.8m points)

statistics - Constant errors when reading data in r

First, I'd like to say I'm pretty new to this whole thing. I've been learning R through my econometrics classes and have constantly been met with the same problem.

When I try to read data into r using read.table or read.csv I always get weird errors. The two most common are that line 1 or 2 contain embedded nulls and that there is an incomplete line somewhere. I want to be clear that this happens on almost every single data set I download. These datasets are all from textbooks (econometrics), or from Coursera classes(namely the John Hopkins Data Science one) so they should be ok. I've also watched my professors import with 0 problems.

Edit: Here's the full error message

data <- read.table(file.choose(), header= TRUE) Warning messages: 1: In read.table(file.choose(), header = TRUE) : line 1 appears to contain embedded nulls 2: In read.table(file.choose(), header = TRUE) : incomplete final line found by readTableHeader on 'C:Users..DesktopData setsProject-11-datafile.xlsx'

I've tried changing the encoding to a few options, using the skipNul command, as well as a few other things I've found here or there. It happens on EVERY dataset so I feel like I did something wrong somewhere

Did I change something or mess something up on the install? Could it be a problem with excel? I've searched everything, tried changing encoding options and it still persists.

The most recent one was here: https://www.core-econ.org/doing-economics/book/text/11-03.html#part-111-summarizing-the-data And I cannot even import due to the warning messages(just using read.table(file.choose(), header= TRUE)

I'm sorry for such a stupid question and I don't know what more details would be useful, but this is driving me absolutely crazy.

Also if it helps I'm on windows 10 and have the Korean language set as the default, if that even matters.

Thanks in advance for anyone taking the time to try and help

question from:https://stackoverflow.com/questions/65935652/constant-errors-when-reading-data-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have two warnings, which appear to be the consequence of two different issues. The first warning probably means you have a header row in the .xlsx file that is empty.

Warning messages: 1: In read.table(file.choose(), header = TRUE) : line 1 appears to contain embedded nulls

I can recreate the error when I have sample data like this, where column C does not have a header.

noHeader

The second warning is triggered by trying to read in .xlsx files with the read.table() function.

In read.table(file.choose(), header = TRUE) : incomplete final line found by readTableHeader on 'C:Users..DesktopData setsProject-11-datafile.xlsx'

But read.table() is not used to import .xlsx files. Instead, you can use a function like readxl::read_xlsx(). Some guidance on how to do that is provided here

So, you may need to edit the Excel file manually to see if there are any blank headers on the data columns. And then install the readxl package to use read_xlsx for importing your .xlsx files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...