1

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?

dPdms
  • 173
  • 2
  • 14

2 Answers2

1

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]
akrun
  • 874,273
  • 37
  • 540
  • 662
1

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"))
Chirayu Chamoli
  • 2,076
  • 1
  • 17
  • 32