gpt4 book ai didi

r - 'T' & 'F' 从数据库中读取为 True 和 False

转载 作者:行者123 更新时间:2023-12-02 01:56:38 25 4
gpt4 key购买 nike

我需要使用 RODBC sqlQuery 函数从其中一列包含“T”和“F”值的数据库中读取数据。然而,我的结果不断出现“真”和“假”。我找到了以下阅读 csv 文件的帖子。 sqlQuery 函数是否有类似的解决方法?

read.table reads "T" as TRUE and "F" as FALSE, how to avoid?

编辑:这是我按照评论中的要求运行的代码。如果不访问数据库,它将无法执行......

conn = odbcConnect(dataBaseName)
results = sqlQuery(conn, paste0("select ID, andate, antime from table.e4 where ticker in (",paste(shQuote(IDvector, type = "sh"), collapse = ', '),");"))
close(conn)

ID是包含'T'和'Fs的字段

最佳答案

sqlQuery 函数有 as.is 选项,来自 the RODBC manual :

as.is which (if any) columns returned as character should be converted to another type? Allowed values are as for read.table. See ‘Details’.

Details
... if as.is is true for a column, it is returned as a character vector. Otherwise (where detected) date, datetime and timestamp values are converted to the "Date" or "POSIXct" class. ...

关于r - 'T' & 'F' 从数据库中读取为 True 和 False,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19632834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com