library("eia")
eia_set_key("MpAjEon2zWULOTOnfJf2olzv3KB8zOgYnILsGVQf")
eia_dir()
eia_dir("petroleum")
eia_dir("petroleum/crd/crpdn/")

TEST <- eia_data( dir = "petroleum/crd/crpdn/",data="value", freq = "annual",start="1990")
#TEST$area-name
TEST$`area-name`
colnames(TEST) <- gsub("-","_",colnames(TEST) )
unique(TEST$area_name)
TEST[grep("PADD",TEST$area_name),]
TEST <- TEST[!grepl("PADD",TEST$area_name),]
unique(TEST$area_name)
TEST[is.na(TEST$area_name),]
TEST[TEST$area_name=="NA",]
TEST <- TEST[TEST$area_name!="NA",]
TEST$area_name <- gsub("USA-","",TEST$area_name)
State_Ab <- state.abb
State_Name <- toupper(state.name)
States <- as.data.frame(cbind(State_Ab,State_Name))
unique(TEST[!(TEST$area_name %in% State_Ab),"area_name"])
TEST$area_name <- ifelse(TEST$area_name=="NEW YORK","NY",TEST$area_name)
TEST$area_name <- ifelse(TEST$area_name=="CALIFORNIA","CA",TEST$area_name)
TEST$area_name <- ifelse(TEST$area_name=="OHIO","OH",TEST$area_name)
TEST$area_name <- ifelse(TEST$area_name=="TEXAS","TX",TEST$area_name)
TEST$area_name <- ifelse(TEST$area_name=="COLORADO","CO",TEST$area_name)
TEST$area_name <- ifelse(TEST$area_name=="FLORIDA","FL",TEST$area_name)
unique(TEST$area_name )

TEST[,c("area_name","period","value")]
?cor

       