How can I read a csv file with unusual delimiters and encoding in R

68 Views Asked by At

I am trying to read a .csv file that uses an unusual delimiter and an unfamiliar (for me) encoding.

After much trial and error, I got the file to read at least, but the result is not very good. What can I do?

download.file('https://www.dropbox.com/scl/fi/kl8a86fiyim15g4op4er4/test_file.csv?rlkey=bx8mozu395r3zkl4ddka9fhsy&dl=1',
              destfile="test_file.csv",
              method="auto")

best_so_far <- read_delim(here("test_file.csv"), delim = '¤', 
                          locale = locale(encoding = "ISO-8859-1"), 
                          quote = "")

I did manage to import it to google sheets (where you can set a custom delimiter). It's har to know what google sheets does behind the scenes. Heres what it looks like:

7   150 3   2   2   99999998        99999998    99999998    99999998    99999998    99999998    99999998        3       99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998    99999998        99999998    17579   1 000 st 20 - 199   20-199 anställda    Bildelar & -tillbehör, partihandel  45310   100 64  STOCKHOLM
8   100 3   2   2   99999998        99999998    99999998    99999998    99999998    99999998    99999998        3       99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998    99999998        99999998    17579   1 000 st 20 - 199   20-199 anställda    Dagstidningsförlag  58131   100 64  STOCKHOLM
14  400 3   2   2   99999998        99999998    99999998    99999998    99999998    99999998    99999998        3       99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998    99999998        99999998    99999998    99999998    99999998    99999998    99999998        99999998    17579   1 000 st 20 - 199   20-199 anställda    Personal, uthyrning 78200   101 32  STOCKHOLM

It might be helpful to know that its supposed to be answers to, at least one, survey.

EDIT: Sample rows

7¤150¤3¤2¤2¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤3¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤17579¤1 000 st 20 - 199¤20-199 anställda¤Bildelar & -tillbehör, partihandel¤45310¤100 64¤STOCKHOLM
8¤100¤3¤2¤2¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤3¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤99999998¤99999998¤99999998¤99999998¤99999998¤¤99999998¤17579¤1 000 st 20 - 199¤20-199 anställda¤Dagstidningsförlag¤58131¤100 64¤STOCKHOLM
0

There are 0 best solutions below