in ,

R: Getting and Importing Data

R can directly import data from URL’s by using the following syntax:

fileCameras <- "https://data.baltimorecity.gov/api/views/hdyb-27ak/rows.csv?accessType=DOWNLOAD"
download.file(fileCameras, destfile="baltimore_cameras.csv",method="curl")

The first assignment sets the variable fileCameras to the URL for the csv. How I got that URL was by going to the public dataset for the Baltimore city database. I went to CCTV cameras and right clicked the CSV option on the export tab. I copied the URL for the CSV file and pasted it in as the value for fileCameras.

After that I made use of the R command download, and it’s method .file. The .file method takes three params: The file path (URL), the destination on your hard drive for saving it and the method. I’ve been told that the method is optional on a PC, but on MAC curl is required as it’s value.

Once you do these commands the CSV will download to your local directory that you are in, in R.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Comments

Leave a Reply

Loading…

Python Cache

R: Reading Data