What is the problem and/or difference between reading a file in .txt
and .xlsx
in R?
Strictly speaking, none. Both are valid ways to store data for analysis, as well as .csv
, .sav
and .dat
are also. The only drawback in using .xlsx
requires, almost necessarily, a spreadsheet editor to view the files, while the format .txt
can be read pro virtually any program installed on the computer.
Reading in .xlsx
can have more problems than in .txt
during an analysis?
If reading both files was done correctly, no problems should occur while analyzing the data.
A friend asked me to do everything in .txt
because it’s better but I don’t understand why.
See the first answer I gave. Also, it might just be his personal preference. Particularly, I prefer files .txt
and .csv
because I can read them directly on the terminal without needing additional programs. In addition to, of course, the disk space occupied by files .txt
is smaller than the space occupied by files .xlsx
(although these days this is not so relevant).
Another detail is that I have a file in . xlsx with 4 tabs (Sheets) and when I change the name of the tab in the script it continues reading the previous one. This is due to be Excel?
I can’t answer this question because I don’t have your code available. So, I can’t evaluate what could be wrong in it or even in the file .xlsx
to be read. What I can say is that I use something similar to the code below when I work with people who use Excel and this code, when adapted to the needs of each analysis, works very well, even in files .xlsx
with more than one sheet. I just change the parameter sheet=1
for sheet=2
in order to read a different sheet. I do not call them by name, but rather by position within the file .xlsx
.
library(readxl)
read_excel("arquivo.xlsx", sheet=1, col_names=TRUE)
read_excel("arquivo.xlsx", sheet=2, col_names=TRUE)
Note that you need to install the package readxl
before running the above commands.
Dear Marcos Nunes and Marcelo de Andrade. Thank you very much for your answer and enlightening, really helped me a lot. As for the error I reported, it has already been corrected. There was an extra space, which I had not noticed. I already have more than one package for excel, xlsx and the one you told me about. As I am a beginner in R we will probably talk other times and of course vc always helping with direct answers. Thank you very much
– Herlon Nadolny
That’s good to know, Herlon. Since the answer was helpful, consider voting for it as explained in this link, as users of the site are rewarded and feel compelled to continue helping other users.
– Marcus Nunes