You have to fill in details, but something like this would work:

###
install.packages("foreign")
require(foreign)

setwd("xxx") # to where your directory of files is
filenames <- dir() # a vecto of file names (if this folder has only the files you want to read in)
dbf_dfs <- lapply(filenames, read.dbf) # makes a list of the data frames read (you can pass other options to read.dbf as a list of vector possibly, after you list the function in lapply)





SAC 

______________________Scott Chamberlain
Rice University, EEB Dept.


On Sunday, August 7, 2011 at 4:33 PM, Travis Belote wrote:

> Hi all,
> 
> I have about 300 small dbf tables that I would like to combine into one long table. All 300 tables have the exact same structure (13 rows x 10 columns) and the only way to know what the data represent is from the filename. So, I would like to somehow take the file name and add it to each table repeated in a new column, then combine all tables. For instance the file "ppt00apr.dbf" looks like this:
> 
> 
> LEVEL3_NAM
> 
> ZONE_CODE
> 
> COUNT
> 
> AREA
> 
> MIN
> 
> MAX
> 
> RANGE
> 
> MEAN
> 
> STD
> 
> SUM
> 
> Columbia Plateau
> 
> 1
> 
> 256
> 
> 0.444
> 
> 22.000
> 
> 68.000
> 
> 46.000
> 
> 45.789
> 
> 10.490
> 
> 11722.000
> 
> Northern Rockies
> 
> 2
> 
> 4156
> 
> 7.215
> 
> 14.000
> 
> 178.000
> 
> 164.000
> 
> 64.051
> 
> 24.852
> 
> 266194.000
> 
> Canadian Rockies
> 
> 3
> 
> 1309
> 
> 2.273
> 
> 13.000
> 
> 190.000
> 
> 177.000
> 
> 70.468
> 
> 29.451
> 
> 92243.000
> 
> Northwestern Glaciated Plains
> 
> 4
> 
> 6653
> 
> 11.550
> 
> 3.000
> 
> 63.000
> 
> 60.000
> 
> 20.445
> 
> 7.257
> 
> 136021.000
> 
> Middle Rockies
> 
> 5
> 
> 7019
> 
> 12.186
> 
> 1.000
> 
> 171.000
> 
> 170.000
> 
> 35.874
> 
> 19.355
> 
> 251801.000
> 
> Northwestern Great Plains
> 
> 6
> 
> 10283
> 
> 17.852
> 
> 11.000
> 
> 82.000
> 
> 71.000
> 
> 29.856
> 
> 8.629
> 
> 307008.000
> 
> Blue Mountains
> 
> 7
> 
> 456
> 
> 0.792
> 
> 8.000
> 
> 73.000
> 
> 65.000
> 
> 34.250
> 
> 10.862
> 
> 15618.000
> 
> Idaho Batholith
> 
> 8
> 
> 3963
> 
> 6.880
> 
> 4.000
> 
> 114.000
> 
> 110.000
> 
> 49.370
> 
> 16.512
> 
> 195653.000
> 
> Snake River Plain
> 
> 9
> 
> 3266
> 
> 5.670
> 
> 3.000
> 
> 52.000
> 
> 49.000
> 
> 19.040
> 
> 7.865
> 
> 62183.000
> 
> Northern Basin and Range
> 
> 10
> 
> 2335
> 
> 4.054
> 
> 6.000
> 
> 69.000
> 
> 63.000
> 
> 25.663
> 
> 9.216
> 
> 59923.000
> 
> Wyoming Basin
> 
> 11
> 
> 166
> 
> 0.288
> 
> 5.000
> 
> 40.000
> 
> 35.000
> 
> 19.874
> 
> 7.110
> 
> 3299.000
> 
> Central Basin and Range
> 
> 12
> 
> 89
> 
> 0.155
> 
> 15.000
> 
> 44.000
> 
> 29.000
> 
> 26.124
> 
> 6.211
> 
> 2325.000
> 
> Wasatch and Uinta Mountains
> 
> 13
> 
> 107
> 
> 0.186
> 
> 12.000
> 
> 76.000
> 
> 64.000
> 
> 40.776
> 
> 16.121
> 
> 4363.000
> 
> 
> I would like to add the filename so that the table would look like:
> 
> LEVEL3_NAM
> 
> Filename
> 
> ZONE_CODE
> 
> COUNT
> 
> AREA
> 
> MIN
> 
> MAX
> 
> RANGE
> 
> MEAN
> 
> STD
> 
> SUM
> 
> Columbia Plateau
> 
> ppt00apr
> 
> 1
> 
> 256
> 
> 0.444
> 
> 22.000
> 
> 68.000
> 
> 46.000
> 
> 45.789
> 
> 10.490
> 
> 11722.000
> 
> Northern Rockies
> 
> ppt00apr
> 
> 2
> 
> 4156
> 
> 7.215
> 
> 14.000
> 
> 178.000
> 
> 164.000
> 
> 64.051
> 
> 24.852
> 
> 266194.000
> 
> Canadian Rockies
> 
> ppt00apr
> 
> 3
> 
> 1309
> 
> 2.273
> 
> 13.000
> 
> 190.000
> 
> 177.000
> 
> 70.468
> 
> 29.451
> 
> 92243.000
> 
> Northwestern Glaciated Plains
> 
> ppt00apr
> 
> 4
> 
> 6653
> 
> 11.550
> 
> 3.000
> 
> 63.000
> 
> 60.000
> 
> 20.445
> 
> 7.257
> 
> 136021.000
> 
> Middle Rockies
> 
> ppt00apr
> 
> 5
> 
> 7019
> 
> 12.186
> 
> 1.000
> 
> 171.000
> 
> 170.000
> 
> 35.874
> 
> 19.355
> 
> 251801.000
> 
> Northwestern Great Plains
> 
> ppt00apr
> 
> 6
> 
> 10283
> 
> 17.852
> 
> 11.000
> 
> 82.000
> 
> 71.000
> 
> 29.856
> 
> 8.629
> 
> 307008.000
> 
> Blue Mountains
> 
> ppt00apr
> 
> 7
> 
> 456
> 
> 0.792
> 
> 8.000
> 
> 73.000
> 
> 65.000
> 
> 34.250
> 
> 10.862
> 
> 15618.000
> 
> Idaho Batholith
> 
> ppt00apr
> 
> 8
> 
> 3963
> 
> 6.880
> 
> 4.000
> 
> 114.000
> 
> 110.000
> 
> 49.370
> 
> 16.512
> 
> 195653.000
> 
> Snake River Plain
> 
> ppt00apr
> 
> 9
> 
> 3266
> 
> 5.670
> 
> 3.000
> 
> 52.000
> 
> 49.000
> 
> 19.040
> 
> 7.865
> 
> 62183.000
> 
> Northern Basin and Range
> 
> ppt00apr
> 
> 10
> 
> 2335
> 
> 4.054
> 
> 6.000
> 
> 69.000
> 
> 63.000
> 
> 25.663
> 
> 9.216
> 
> 59923.000
> 
> Wyoming Basin
> 
> ppt00apr
> 
> 11
> 
> 166
> 
> 0.288
> 
> 5.000
> 
> 40.000
> 
> 35.000
> 
> 19.874
> 
> 7.110
> 
> 3299.000
> 
> Central Basin and Range
> 
> ppt00apr
> 
> 12
> 
> 89
> 
> 0.155
> 
> 15.000
> 
> 44.000
> 
> 29.000
> 
> 26.124
> 
> 6.211
> 
> 2325.000
> 
> Wasatch and Uinta Mountains
> 
> ppt00apr
> 
> 13
> 
> 107
> 
> 0.186
> 
> 12.000
> 
> 76.000
> 
> 64.000
> 
> 40.776
> 
> 16.121
> 
> 4363.000
> 
> 
> I'd like to do this 300 times and combine all of the smaller tables into one long table.
> 
> Can anyone help me with some R code? I'm fairly new to R and am pretty ignorant. I can imagine some kind of appending function with a loop, but don't know how to get started.
> 
> Thank you all very much for your help.
> 
> Sincerely,
> Travis
> 
> R. Travis Belote
> The Wilderness Society
> Research Department
> Northern Rockies Regional Office
> 503 W Mendenhall St.
> Bozeman, MT 59715-3450
> 
> Office (406) 586-1600 ext. 110; Home (406) 587-2098; Cell (406) 581-3808
> Email: travis_belote@tws.org<mailto:travis_belote@tws.org>
> Web: http://wilderness.org/about-us/experts/travis-belote
> 
> 
> 
> 
>  [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org (mailto:R-sig-ecology@r-project.org)
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


	[[alternative HTML version deleted]]

