Relief, however, is at hand to all such denizens, for Springer have now made available a (somewhat small) selection of their books available for download online, chapter-by-chapter. Find them at:
Saturday, September 11, 2010
Resources for texts in Statistics and Mathematics
For all those who (like me!) dream of building up a nice collection of statistics and mathematics texts, the Springer series texts are the stuff of which dreams,, and nightmares!, are at the same time made up of; the former due to the range of good books, the latter owing to the price-gouging indulged in by Springer.
Wednesday, September 8, 2010
Reading in multiple files interactively with R
Many, like me, will have had occasion to do the following: read a few files (say .txt files, for instance) from a known folder, and then (possibly after some manipulations/computations) plot the contents in the files (or some transformations thereof). The important thing is that when these computations are repeated after a few days/weeks/months, we must again locate all the files (worry about whether those files are in the same folders etc) and since R is not really GUI, there is the pain of finding the snippets of code where the folder locations and file names are hard wired. A simpler means would allow the user to either specify a folder (but not the file names) or to even search for a folder in which to search for the required files, and that is what is described below.
Effectively, I will illustrate the R command "choose.files" (see here for more details) from "utils" package.
What I carry out below, using this command is to read in, from the folder specified below, many files (all of which have the same extension, .txt, in this example, although that is not necessary).
This snippet does the reading in the file paths part (the difficult part):
test=choose.files(default = "C:/MyFolder/*.*", caption = "Select files",
multi = TRUE, filters = Filters[c("txt", "All"),],
index = nrow(Filters))
where "default=C:\*.*" indicates the folder from which to read the files, and that all possible files in that folder are to be displayed. In this case, the option "filer" is actually redundant, and therefore, I could just as easily have written
test=choose.files(default = "C:/MyFolder/*.*", caption = "Select files",
multi = TRUE )
instead.
Of course, having read the full path of the files in, one can simply read the said files in as below:
NFiles=length(test)
Data=vector(mode="list",NFiles)
for (i in 1:NFiles) {
Data[[i]]=read.table(test[i],header=F)
}
As simple, and powerful, as that!
Subscribe to:
Posts (Atom)