My sqldf set up in R uses SQLite by default. I tried the following query without success:
query = "UPDATE t1
SET Actual = t2.AvgRevenue,
Total = t2.AvgRevenue
WHERE Name=t2.Name AND
Pillar= 'HW' AND
(Status <> 'Lost') AND
Revenue=0"
t1 = sqldf(c(query,"select * from pl0"))
t1 has columns Name, Pillar, Status, Revenue, Actual, Total t2 is a lookup table with columns Name, AvgRevenue
After doing some research, I found that SQLite does not currently support UPDATE queries involving two or more tables.
My question is this: can I do the equivalent of the query above using only R?
To get an answer, I tried the following:
test <- t1[t1$Revenue == 0 & t1$Status == 'Lost' & t1$Pillar == 'HW',]
test$Actual <- test$Name
mapvalues(test$Actual,
t2$Name,
t2$AvgRevenue,
warn_missing = FALSE)
t1 <- test
but mapvalues is not updating column test$Actual as I expected. The right values of t2$AvgRevenue are output to the console, but test$Actual is not updated. By the way, I want t1 to be the same data frame as before, but with the appropriate rows in columns Actual and Total updated.
Any suggestions will be greatly appreciated!