HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Reading an ascii file into R Studio #60

Closed KatrinHeger closed 8 years ago

KatrinHeger commented 8 years ago

FYI I was trying to read this file (http://privatewww.essex.ac.uk/~ksg/data/nsa_v3.4_21November2013.asc) into R but it was not working. I got the "more columns than column names" error message. This is the website from wich I wanted to download the file: http://privatewww.essex.ac.uk/~ksg/eacd.html.

Christopher helped me out:

"I don't really know why this researcher made a point of referring to the file as ASCII. This refers to the character encoding (e.g. UTF-8) rather than how the data is formatted overall (e.g. csv). I guess they just wanted to point out that it was a text file? Anyways, If you open the file in a text editor with invisible characters turned on, you can see that columns are tab-separated (like comma separated (csv), but tabs instead of commas). So, simply use:

library(rio)
dyads <- import('http://privatewww.essex.ac.uk/~ksg/data/nsa_v3.4_21November2013.asc', 
                format = 'tsv')

'tsv' for tab-separated. And this should work."

It did work!