How to convert .dat to csv in Julia? - julia

I have a dataset with the .dat format, I want to read it but I can't. What is the solution? I tried readtable() from DataFrames.jl but I get the "Invalid UTF-8 string" error.

Related

How to read my excel as strings in R? (R reads my excel file as date format)

I am trying to read an excel file in R.
I used read_excel() function.
My excel file is full of numbers such as 18116.28
But R seems to recognize the numbers as date and time.
R read this as 1949-08-06 06:49:24
Why does this happen? And how can I stop this?

Saving Umlauts in a .csv in R

I am trying to save a dataframe into a csv file. The dataframe contains umlauts, which I want to keep.
I tried exporting with
write.csv2(x, fileEncoding = "UTF-8")
as well as
readr::write_csv2(x)
in both cases, the umlauts do not get exported correctly. Instead of ä weird symbols occur: ä . My R is set to save files as UTF-8 as well. Is there something else I can try?

How to read csv file with unknown formatting and unknown encoding in R Program? (example file provided)

I have tried my best to read a CSV file in r but failed. I have provided a sample of the file in the following Gdrive link.
Data
I found that it is a tab-delimited file by opening in a text editor. The file is read in Excel without issues. But when I try to read it in R using "readr" package or the base r packages, it fails. Not sure why. I have tried different encoding like UTF-8. UTF-16, UTF16LE. Could you please help me to write the correct script to read this file. Currently, I am converting this file to excel as a comma-delimited to read in R. But I am sure there must be something that I am doing wrong. Any help would be appreciated.
Thanks
Amal
PS: What I don't understand is how excel is reading the file without any parameters provided? Can we build the same logic in R to read any file?
This is a Windows-related encoding problem.
When I open your file in Notepad++ it tells me it is encoded as UCS-2 LE BOM. There is a trick to reading in files with unusual encodings into R. In your case this seems to do the trick:
read.delim(con <- file("temp.csv", encoding = "UCS-2LE"))
(adapted from R: can't read unicode text files even when specifying the encoding).
BTW "CSV" stands for "comma separated values". This file has tab-separated values, so you should give it either a .tsv or .txt suffix, not .csv, to avoid confusion.
In terms of your second question, could we build the same logic in R to guess encoding, delimiters and read in many types of file without us explicitly saying what the encoding and delimiter is - yes, this would certainly be possible. Whether it is desirable I'm not sure.

How to output a file with Chinese Character into .csv file that's compatible with excel?

I want to export the data.frame with character vector in Chinese.
I have tried to output it into text file, it works perfectly with the following code
Sys.setlocale(category = "LC_ALL", locale = "zh_cn.utf-8")
data<-data.frame(ID=c('小李','小王','小宗'),number=c(1:3))
write.table(data,'test.txt',quote=F,row.names=F,sep='\t')
But when I tried to use the write.csv, if I use excel to open the data file, the Chinese part of the data is not correct for the output test.csv, see the figure below for details.
write.csv(data,'test.csv',row.names=F)
I have found a similar post on stackoverflow, but failed to figure out how to cope with my case. How to export a csv in utf-8 format?.
Is there any solution that can output the data file that is compatible with excel?

How to read Unicode file in R

I have one unicode (UTF-8) file with column delimiter as 'þ', I'm trying to read it using R csv reader as follows
data <- read.csv(file_name,,sep="þ",encoding="UTF-8")
in my data frame I'm getting everything in a single column, can someone correct me what I'm doing wrong here?
I think your script needs to be encoded as utf-8 too if you're using non-ascii characters.
Save your code in for example myfile.r and then
Try this:
source("myfile.r", encoding="utf-8")
hopefully your error will go away

Resources