我正试图从访问中将数据拉入R,我已经成功完成了。
现在我要做的是将一行代码与一次一个代码相对应地拉入所有需要的表。
示例:
我有5张桌子: 3/15政策细节 6/15政策细节 9/15政策细节 12/15政策细节 3/16政策细节
如您所见,所有表格都以“政策详细信息”结尾,但以不同的日期开头。
我的原始解决方案:
library(RODBC)
db<-file.path("C:\\Path\\To\\Database.accdb")
db
channel<-odbcConnectAccess2007(db)
sqlTables(channel,tableType = "TABLE")$TABLE_NAME ##List all table names
Q1.15<-sqlFetch(channel,"3/15 Policy Details")
Q2.15<-sqlFetch(channel,"6/15 Policy Details")
close(channel)
我必须为每个quater使用sqlFetch。我要做的是将所有表格与一串代码相对应,以便为每个季度执行单独的代码行。
答案 0 :(得分:2)
考虑在返回的表名列表中使用[
{
"week_start": "8/01/2016",
"week_end": "8/06/2016"
}, {
"week_start": "8/07/2016",
"week_end": "8/13/2016"
}, {
"week_start": "8/14/2016",
"week_end": "8/20/2016"
}, {
"week_start": "8/21/2016",
"week_end": "8/27/2016"
}, {
"week_start": "8/28/2016",
"week_end": "9/03/2016"
}, {
"week_start": "9/04/2016",
"week_end": "9/10/2016"
}, {
"week_start": "9/11/2016",
"week_end": "9/17/2016"
}, {
"week_start": "9/18/2016",
"week_end": "9/24/2016"
}, {
"week_start": "9/25/2016",
"week_end": "10/01/2016"
}, {
"week_start": "10/02/2016",
"week_end": "10/08/2016"
}
]
。然后将表格提取绑定到包含grep()
的列表,然后将数据框对象与lapply()
分开:
list2env