I am facing with two questions of sqldf in R studio:
1- I want to control one variable's value in sqldf's where clause. However, I tried several ways: it doesn't work well. I want that control[i] can change where condition in each run. Can anyone help on this?
control = c(16,18)
for (i in 1:2){
label <- paste("data",i,sep="_")
assign(label,fn$sqldf("select *
where time between '20170502' and '20170504' or
sales between 'control[i]' and '23' ))
}
Secondly, The following code didn't work as well in sqldf.
test1 <- sqldf("select *, (case when time between '20170530 00:00:00' and '20170530 03:00:00' then 1 else 0 end) as newdata from olddata")
The data type show in R is [1] "POSIXct" "POSIXt" . Attached example data as below:
time sales
2017/5/01 01:00:00 1249
2017/5/03 12:00:00 1683
2017/5/04 13:00:00 1909
2017/5/06 06:00:00 1686
2017/5/08 18:00:00 1500
2017/5/25 04:00:00 11586
2017/5/30 04:00:00 11834
2017/5/28 04:00:00 11909
2017/5/30 03:00:00 11962
2017/5/30 01:00:00 12500