I have downloaded the data and would like to change columns named USD and EUR to numeric and also treat the column date as a date. I would also like to get rid of the missing values in the dataframe named result3.
library(dplyr)
library(ggplot2)
library(reshape2)
getNBPRates <- function(year) {
url1 <- sprintf(
paste0("https://www.nbp.pl/kursy/Archiwum/archiwum_tab_a_", year, ".csv"),
year)
url1 <- read.csv2(url1, header=TRUE, sep=";", dec=",") %>%
select(data, X1USD, X1EUR) %>%
rename(usd=X1USD, eur=X1EUR, date=data) %>%
slice(-1)
transform(url1, date = as.Date(as.character(date), "%Y%m%d"))
}
a <- getNBPRates(year=2015)
head(as.data.frame(a))
years<- c(2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020)
result <- lapply(years, getNBPRates)
result3 <- Reduce(rbind, result)
Error: object 'getNBPRates' not found. Also,Reduce(rbind, result)is horribly inefficient and will get very slow with more data; use insteaddo.call(rbind, result). The difference is that withReduce, rbind is copiedn-1times (wherenislength(years)here), and with each time it makes a complete copy of the data in memory ... eventually that gets big and slow; withdo.call, rbind is called only once. No copying-over-copying-over-copying ...