I'm trying to read in a csv file from github in R. However, when I try to get the names of the columns, I only get one name

Viewed 2834

I'm running this code to import the csv file into movies.

movies <-read.csv("https://github.com/fivethirtyeight/data/blob/master/fandango/fandango_score_comparison.csv",header=TRUE) 
names(movies)

Here I'm trying to get the names of the columns

{r seeing variable names,echo=FALSE} names(movies)

All I get is this

[1] "X..DOCTYPE.html."

What am I missing?

1 Answers

When reading data from github, you need to pass in the raw version of the data in read.csv(), you are using the display version. You can get the URL for the raw version by clicking on the Raw button displayed above the data.

enter image description here

movies <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/fandango/fandango_score_comparison.csv", header=TRUE)
Related