我正在处理大数据集和tidyr的
spread
通常会给我错误信息,提示
failure to obtain memory
因此,我一直在探索
dbplyr
. 然而,正如它所说
here
dbplyr::spread()
不起作用。
我的问题是是否有其他方法来完成
tidyr::spread
在工作时
tbl_dbi
tbl_sql
不下载到本地存储器的数据。
使用来自
,下面我将介绍我得到的以及我想做的和得到的。
#tbl_dbi和tbl_sql数据示例
df_sample <- tribble(~group1, ~group2, ~group3, ~identifier, ~value,
8, 24, 6, 'mt_0',
12, 18, 24, 6, 'mt_1', 4)
con <- DBI::dbConnect(RSQLite::SQLite(), "")
df_db <- copy_to(con, df_sample, 'df_sample')
#尝试在不下载到本地内存的情况下传播tbl\u dbi和tbl\u sql
//this does not work
df_db %>% spread(identifier, value)
Error in UseMethod("spread_") :
no applicable method for 'spread_' applied to an object of class "c('tbl_dbi', 'tbl_sql', 'tbl_lazy', 'tbl')"
//this spreads the data but the output is in memory
//I would like to keep the output as 'tbl_dbi', 'tbl_sql', and 'tbl_lazy'
df_db %<>% collect() %>% spread(identifier, value)
class(df_db)
[1] "tbl_df" "tbl" "data.frame"
提前谢谢你的帮助