1

I have a dataset given in .dbf format and need to import it into R. I haven't worked with such extension previously, so have no idea how to export dbf file with multiple tables into different format.

Simple read.dbf has been running hours and still no results. Tried to look for speeding up R performance, but not sure whether it's the case, think the problem is behind reading the large dbf file itself (weights ~ 1.5Gb), i.e. the command itself must be not efficient at all. However, I don't know any other option how to deal with such dataset format. Is there any other option to import the dbf file?

P.S. (NOT R ISSUE) The source of the dbf file uses visual foxpro, but can't export it to other format. I've installed foxpro, but given that I've never used it before, I don't know how to export it in the right way. Tried simple "Export to type=XLS" command, but here comes a problem with encoding as most of variables are in Russian Cyrillic and can't be decrypted by excel. In addition, the dbf file contains multiple tables that should be merged in 1 big table, but I don't know how to export those tables separately to xls, same as I don't know how to export multiple tables as a whole into xls or csv, or how to merge them together as I'm absolutely new to dbf files theme (though looked through base descriptions already)

Any helps will be highly appreciated. Not sure whether I can provide with sample dataset, as there are many columns when I look the dbf in foxpro, plus those columns must be merged with other tables from the same dbf file, and have no idea how to do that. (sorry for the mess)

4

1 回答 1

3

根据 VFP 帮助文件,您可以通过命令行窗口使用 COPY TO 命令以多种格式从 Visual FoxPro 导出。

例如:

use mydbf in 0
select mydbf
copy to myfile.xls type xl5
copy to myfile.csv type delimited

如果您遇到与语言相关的问题,可以在这些问题的末尾添加“as codepage”子句。例如:

copy to myfile.csv type delimited as codepage 1251

如果您不熟悉 VFP,我会尝试像这样将原始数据提取出来,然后放到您熟悉的平台中然后再尝试合并等。

要在循环中导出它们,您可以在 .PRG 文件中使用以下内容(修改顶部的两个路径变量以反映您自己的设置)。

    Close All
Clear All
Clear 

lcDBFDir = "c:\temp\"           && -- Where the DBF files are.
lcOutDir = "c:\temp\export\"        && -- Where you want your exported files to go.

lcDBFDir = Addbs(lcDBFDir)      && -- In case you forgot the backslash.
lcOutDir = Addbs(lcOutDir)  

* -- Get the filenames into an array.
lnFiles = ADir(laFiles, Addbs(lcDBFDir) + "*.DBF")

* -- Process them. 
For x = 1 to lnFiles

    lcThisDBF = lcDBFDir + laFiles[x, 1]
    Use (lcThisDBF) In 0 Alias currentfile
    Select currentfile
    Copy To (lcOutDir + Juststem(lcThisDBF) + ".csv") type csv
    Use in Select("Currentfile")        && -- Close it.

EndFor

Close All

...并从命令行窗口运行它 - 执行 myprg.prg 或其他任何操作。

于 2013-07-03T09:36:06.227 回答