Skip to content

Instantly share code, notes, and snippets.

@robsalasco
Created January 7, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsalasco/5a658b8468cd789e88cc905e9b44279a to your computer and use it in GitHub Desktop.
Save robsalasco/5a658b8468cd789e88cc905e9b44279a to your computer and use it in GitHub Desktop.
library(httr)
library(jsonlite)
uf <- function(x, year, apikey) {
response <- GET(paste0("http://api.sbif.cl/api-sbifv3/recursos_api/uf/",year,"?apikey=",apikey,"&formato=json"))
data <- fromJSON(txt=content(response))$UFs
data$Valor <- sub("\\.","",data$Valor)
data$Valor <- sub("\\,",".",data$Valor)
data$Valor <- as.numeric(data$Valor)
media <- mean(data$Valor)
return(x*media)
}
convert <- c(1,2,3,4,5,6,7,8)
uf(convert,"2017","")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment