0

I am trying to recode variable in R SQL. Below is syntax for the same.

Data[,1] <- recode(Data[,1]," 'Yes' = 1; 'No' = 0 " )

But when we use single quote in R SQL (') it terminate the R SQL command, in R SQL we had to write R script within two single quotes

Can anyone help me here if I can write recode syntax without single quote in R, or is there any alternate option for R SQL

user3734568
  • 1,311
  • 2
  • 22
  • 36
  • @docendodiscimus Thanks for your reply. I tried above syntax but it is not working basically I am trying to execute R script from SQL server where we can write R script between single quotes only – user3734568 May 09 '17 at 09:49
  • Would the [sqlserver] tag be more appropriate than the [rsqlite] tag? – krlmlr May 09 '17 at 20:01

1 Answers1

0

You could try:

Data[,1] <- ifelse(Data[,1] == 1, "Yes", "No")

This uses a different function that doesn't require quotes inside quotes inside quotes. (This assumes that Data[, 1] contains numbers and you want to change that to strings.)

krlmlr
  • 25,056
  • 14
  • 120
  • 217
  • Thanks for your reply. I am trying to check how I can use above suggestion which you have mentioned, but my Data[,1] contains string value so above code is not helping. For Example if I change code to Data[,1] <- ifelse(Data[,1] == Yes, "1", "0") R gives error – user3734568 May 11 '17 at 11:32