有沒有辦法將R數據框中的日期作爲字符串存儲在使用RSQLite的SQLite中?目前,日期列存儲爲整數。在寫入SQLite之前,我可能會將所有日期轉換爲字符串,但由於我需要從函數寫入SQLite,因此數據框架是參數之一,我寧願避免這種轉換。RSQLite - 將日期列存儲爲SQLite中的字符
library('RSQLite')
df <- data.frame(
x=1:3,
y=as.Date(c('2011-01-01','2011-03-03','2011-12-31'))
)
df
# Create connection and temporary database
sqlite <- dbDriver("SQLite")
tmpdb <- dbConnect(sqlite,"__this_is_temporary_db__.db")
# Write data
dbWriteTable(tmpdb,'df',df)
# We get integers from date
dbGetQuery(tmpdb,'select * from df')
dbDisconnect(tmpdb)
# file.remove('__this_is_temporary_db__.db')
見https://github.com/rstats-db/RSQLite/issues/17 – hadley