dPdms
dPdms

Reputation: 173

How to do MySQL update query in r

In MySQL, what I did is:

update table set group = 1 where log(id) < 0

I wanna do same thing in R but I have no idea

What should I do?

Upvotes: 1

Views: 790

Answers (2)

Chirayu Chamoli
Chirayu Chamoli

Reputation: 2076

Using sqldf: You cannot use group as the variable name so im changing to catg.

sqldf(c("update table set catg = 1 where log(id) < 0", "select * from main.xy"))

Upvotes: 1

akrun
akrun

Reputation: 887138

We can use data.table in R. Convert the 'data.frame' to 'data.table' (setDT(tab)), using the logical condition in 'i', we assign (:=) 1 to 'group' variable. As this does in place, it would be much faster and efficient.

library(data.table)
setDT(tab)[log(id) <0, group := 1]

Upvotes: 1

Related Questions