Import flat files from the web
In the video, you saw that the utils functions to import flat file data, such as read.csv() and read.delim(), are capable of automatically importing from URLs that point to flat files on the web.
You must be wondering whether Hadley Wickham's alternative package, readr, is equally potent. Well, figure it out in this exercise! The URLs for both a .csv file as well as a .delim file are already coded for you. It's up to you to actually import the data. If it works, that is…
Deze oefening maakt deel uit van de cursus
Intermediate Importing Data in R
Oefeninstructies
- Load the
readrpackage. It's already installed on DataCamp's servers. - Use
url_csvto read in the.csvfile it is pointing to. Use theread_csv()function. The.csvcontains column names in the first row. Save the resulting data frame aspools. - Similarly, use
url_delimto read in the online.txtfile. Use theread_tsv()function and store the result aspotatoes. - Print
poolsandpotatoes. Looks correct?
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Load the readr package
# Import the csv file: pools
url_csv <- "http://assets.datacamp.com/production/course_1478/datasets/swimming_pools.csv"
# Import the txt file: potatoes
url_delim <- "http://assets.datacamp.com/production/course_1478/datasets/potatoes.txt"
# Print pools and potatoes