[R] Reading multiple files into R
Vikas Rawal
vikas at mail.jnu.ac.in
Sun Oct 3 04:28:02 CEST 2004
I progressed when I combined the Kevin-Roger method with the
Jomes-holtman method. sprintf() in place of formatC did the trick.
Holtman's method does not work because of some problem with the assign.
It seems you cannot have a variable target of the assignment.
Now I have a vector of lists res. I would like to append all these
components into one single dataframe.
I tried the following:
rbind(for (i in 1:17) res[[i]]) -> distvc
But this will not work. It works if I individually specify all the res
components.
Vikas
***************
Holtman's method:
for (i in 1:30){
assign(paste('dist', i, sep=''),
maptools:::dbf.read(sprintf("wb-%02dvc.dbf",i)))
}
Roger's method
>>
>> res <- vector(mode="list", length=9)
>> for (i in 1:length(res)) res[[i]] <-
>> maptools:::dbf.read(paste("wb-0", i, "vc.dbf", sep=""))
>>
>>
>>> res <- vector(mode="list", length=9)
>>> for (i in 1:length(res)) cat(paste("wb-0", i, "vc.dbf", sep=""), "\n")
>>
>>
>> wb-01vc.dbf wb-02vc.dbf wb-03vc.dbf ...
>>
>> gives a check on what file names are being used.
>>
>> For 10 to 99 preserving the 01-09, use paste("wb-", formatC(i,
>> width=2, flag="0"), "vc.dbf", sep="").
>>
>> If the token is a character (string) that varies, you can roll out a
>> character vector of tokens first and step along it.
>>
>>
>>> res <- vector(mode="list", length=length(LETTERS))
>>> for (i in 1:length(res)) cat(paste("wb-", LETTERS[i], "vc.dbf",
>>> sep=""),
>>
>>
>> + "\n")
>> wb-Avc.dbf wb-Bvc.dbf wb-Cvc.dbf ...
>>
>>
More information about the R-help
mailing list