Read.csv() throws error
read.csv
doesn't read XLS(X) files, only CSV files. Try opening your Excel file in Excel, exporting it to CSV and reissuing your read.csv
command (depending on your system language, you might want to use read.csv2
instead).
Issues importing a csv in R
I finally found the solution!
I was going nuts; even my instructor didn't know how to fix it!
This statement works:
o<-read.csv("C:/Users/Admin/Desktop/-=Data Science=-/11-27-2018/Occ.txt", header=T, sep="\t", fileEncoding="UTF-16LE")
Like I said in my original question: I tried using fileEncoding="UTF-16LE" and it didn't help. After asking the question, I tried using sep="\t", and it didn't help. But using both of them did the trick!
Get embedded nul(s) found in input when reading a csv using read.csv()
Your CSV might be encoded in UTF-16. This isn't uncommon when working with some Windows-based tools.
You can try loading a UTF-16 CSV like this:
read.csv("mycsv.csv", ..., fileEncoding="UTF-16LE")
Reading a csv file in R
The problem was the file is saved as csv file but not exported to csv. So the exportation is necessary for the encoding of the file.
embedded nul in string' error trying to import multiple .csv files en masse from different subdirectories in R
Your files are in the UTF-16 (or UCS-2) character encoding. This means that each character is represented by two bytes. Because the data only contain ASCII characters, the second byte of each character is 0.
Because R is expecting a single-byte-per-character encoding, it thinks the second byte is meant to be a null character, which should not be present in a CSV file.
In addition the files contain a byte-order-mark at the start of the first line, which is being converted to garbage. You need a UTF-16 to UTF-8 converter program. This should also remove the byte order mark (which is not required in UTF-8).
Personally I would do this using the tool iconv. If I were using Windows I would use Cygwin to install it.
for f in *.CSV
do iconv -f UTF-16 -t UTF-8 <"$f" >"${f%.CSV}-utf8.csv"
done
If you don't like this approach there are several other tools listed as answers to this question.
Related Topics
Can the Value.Var in Dcast Be a List or Have Multiple Value Variables
How to Change Positions of X and Y Axis in Ggplot2
How to Resolve Spherical Geometry Failures When Joining Spatial Data
How to Annotate a Reference Line at the Same Angle as the Reference Line Itself
Identify Records in Data Frame a Not Contained in Data Frame B
Efficient String Similarity Grouping
Create Sequential Counter That Restarts on a Condition Within Panel Data Groups
Shiny Renderui Selectinput Returned Null
Why am I Losing Categorical Data in My Regression Summary
Raw Text Strings for File Paths in R
Knitr Wont Compile PDF: "Error in Tools::File_Path_As_Absolute(Output_File)"
Combining S4 and S3 Methods in a Single Function
Convert Factor to Date/Time in R