First, you’ll need to load the RCurl package. If you’ve never used this package before, you’ll want to install it from it’s CRAN page
if(!require(RCurl)) install.packages("RCurl") # If missing package, install from CRAN
## Loading required package: RCurl
## Loading required package: bitops
Instead of downloading the dataset manually, right-click on the download option and copy the Link Address. You can plug this directly into the getURL() function from RCurl.
## Use RCurl to download the dataset from medicare.gov API
url <- getURL("https://data.medicare.gov/api/views/c7us-v4mf/rows.csv?accessType=DOWNLOAD")
Since the url object is the csv file as a string, we’ll use textConnection(url) to read the results as a text file. Finally, we use the read.csv() function to read the connection into R.
## Read in the CSV as a csv
hosp <- read.csv(file = textConnection(url))
# View the structure of the object
str(hosp)
## 'data.frame': 14301 obs. of 23 variables:
## $ Provider.ID : Factor w/ 4767 levels "010001","010005",..: 98 98 98 101 101 101 102 102 102 104 ...
## $ Hospital.name : Factor w/ 4572 levels " HIMA SAN PABLO BAYAMON",..: 612 612 612 3154 3154 3154 3146 3146 3146 2999 ...
## $ Address : Factor w/ 4740 levels " CALLE CONCEPCION VERA AYALA #550 S",..: 2056 2056 2056 4705 4705 4705 2967 2967 2967 2 ...
## $ City : Factor w/ 2891 levels "ABBEVILLE","ABERDEEN",..: 2403 2403 2403 2640 2640 2640 2346 2346 2346 1998 ...
## $ State : Factor w/ 55 levels "AK","AL","AR",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ ZIP.Code : int 99669 99669 99669 99686 99686 99686 99664 99664 99664 99833 ...
## $ County.name : Factor w/ 1530 levels "","ABBEVILLE",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ Phone.number : num 9.07e+09 9.07e+09 9.07e+09 9.08e+09 9.08e+09 ...
## $ Payment.measure.name : Factor w/ 3 levels "Payment for heart attack patients",..: 1 2 3 1 2 3 1 2 3 1 ...
## $ Payment.measure.ID : Factor w/ 3 levels "PAYM_30_AMI",..: 1 2 3 1 2 3 1 2 3 1 ...
## $ Payment.category : Factor w/ 5 levels "Greater than the National Average Payment",..: 5 3 3 5 5 5 5 5 5 5 ...
## $ Denominator : Factor w/ 924 levels "1,001","1,002",..: 924 665 917 924 924 924 924 924 924 924 ...
## $ Payment : Factor w/ 6157 levels "","$10045.00",..: 1 990 576 1 1 1 1 1 1 1 ...
## $ Lower.estimate : Factor w/ 6194 levels "$10,011","$10,013",..: 6194 723 520 6194 6194 6194 6194 6194 6194 6194 ...
## $ Higher.estimate : Factor w/ 6313 levels "$10,269","$11,359",..: 6313 1532 599 6313 6313 6313 6313 6313 6313 6313 ...
## $ Payment.footnote : Factor w/ 4 levels "","1 - The number of cases/patients is too few to report.",..: 2 1 1 2 2 2 2 2 2 2 ...
## $ Value.of.care.display.name: Factor w/ 4 levels "","Value of Care Heart Attack measure",..: 2 3 4 2 3 4 2 3 4 2 ...
## $ Value.of.care.display.ID : Factor w/ 4 levels "","MORT_PAYM_30_AMI",..: 2 3 4 2 3 4 2 3 4 2 ...
## $ Value.of.care.category : Factor w/ 11 levels "","Average mortality and average payment",..: 8 2 2 8 8 8 8 8 8 8 ...
## $ Value.of.care.footnote : Factor w/ 3 levels "","13 - Results cannot be calculated for this reporting period.",..: 2 1 1 2 2 2 2 2 2 2 ...
## $ Measure.start.date : Factor w/ 1 level "07/01/2011": 1 1 1 1 1 1 1 1 1 1 ...
## $ Measure.End.Date : Factor w/ 1 level "06/30/2014": 1 1 1 1 1 1 1 1 1 1 ...
## $ Location : Factor w/ 4767 levels "#1 MEDICAL PARK DRIVE\nBENTON, AR 72015\n(34.572716, -92.585094)",..: 2074 2074 2074 4731 4731 4731 2986 2986 2986 4732 ...
Contact |
|
Hunter Ratliff Email: hunterratliff1@gmail.com |
|
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.