[R] how to work on multiple R objects?...

Constantine Tsardounis costas.magnuse at gmail.com
Tue Jan 3 16:24:17 CET 2006


Hello, Happy New Year!...

I am encountering a problem trying to work on the data that I load in R.

I have loaded to R a series of stock data using
(csv files are named e.g. IBM.R)

length.R <- length(list.files(".", pattern=".R")) # the number of
files with one             #column in the directory "./" ending to
".R"
for (i in 1:length.R) {
assign(read.csv(list.files(".", pattern=".R")[i],
read.csv(list.files(".", pattern=".R")[i])))
}

I would like to perform various tasks on all these objects, but I cannot because
> ls(pattern=".R")[1]
is not a list, but a character string!!!:
	> typeof(ls(pa=".R")[1])
	[1] "character"

Exempli gratia:
> typeof(ls(pattern=".R")[45]) 	
[1] "character"
> ls(pattern=".R")[45] 			 I do not want that:
[1] "wmd.txt.R"
> typeof(wmd.txt.R)			I want that:
[1] "list"

so that I can find the mean of the series on all of these files/loaded
objects with a loop that uses the command
mean(wmd.txt.R) instead of mean("wmd.txt.R") that does not work...

Could you help me, please or propose another way to achieve the same result?

Thank you very much for your assistance,

Tsardounis Constantine




More information about the R-help mailing list