R sqldf parsing/case when 语句不支持的字符
R sqldf parsing/case when statement for unsupported characters
R 由于 sqldf 中不支持的字符而给我一个错误,
例如当我输入以下内容时:
sqldf("select *,
case symptom
when 'Bell's palsy' or 'Facial pain' or 'Facial paralysis' then 'neuropathy'
end as Adverse_event from data")
错误是由于"'"
中贝尔的字。有什么工作可以绕过这个错误吗?并且还正确地捕获了数据中的这种情况。
您应该能够在查询中将单引号撇号加倍,例如
sql <- "select *, case symptom
when 'Bell''s palsy' then 'neuropathy'
when 'Facial pain' then 'neuropathy'
when 'Facial paralysis' then 'neuropathy'
end as Adverse_event
from data"
result <- sqldf(sql)
不过,我会在这里使用 WHERE IN (...)
:
sql <- "SELECT *, CASE WHEN symptom IN ('Bell''s palsy', 'Facial pain', 'Facial paralysis')
THEN 'neuropathy' END AS Adverse_event
FROM data"
sqldf(data)
R 由于 sqldf 中不支持的字符而给我一个错误, 例如当我输入以下内容时:
sqldf("select *,
case symptom
when 'Bell's palsy' or 'Facial pain' or 'Facial paralysis' then 'neuropathy'
end as Adverse_event from data")
错误是由于"'"
中贝尔的字。有什么工作可以绕过这个错误吗?并且还正确地捕获了数据中的这种情况。
您应该能够在查询中将单引号撇号加倍,例如
sql <- "select *, case symptom
when 'Bell''s palsy' then 'neuropathy'
when 'Facial pain' then 'neuropathy'
when 'Facial paralysis' then 'neuropathy'
end as Adverse_event
from data"
result <- sqldf(sql)
不过,我会在这里使用 WHERE IN (...)
:
sql <- "SELECT *, CASE WHEN symptom IN ('Bell''s palsy', 'Facial pain', 'Facial paralysis')
THEN 'neuropathy' END AS Adverse_event
FROM data"
sqldf(data)