library(DBI) library(odbc) con <- dbConnect(odbc(), Driver = "ODBC Driver 17 for SQL Server", Server = "REX\\SQLEXPRESS", Database = "VYUKA_DATABAZE", Trusted_Connection="yes", encoding = "CP1250") dbListTables(con) data<-dbGetQuery(con," SELECT * FROM [dbo].[nakaza_po_dnech] ('2020-08-01','2021-03-31') order by my_order,datum ") data$active_cases<-cumsum(data$nakaza-data$umrti-data$vyleceni) data$active_cases[data$my_order!=1]<-NA plot(data$datum,data$active_cases,type = 'l',xlab="datum",ylab="active cases") data.1<-data[data$datum