how to work on multiple R objects?...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to work on multiple R objects?...

Constantine Tsardounis
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: how to work on multiple R objects?...

Sean Davis



On 1/3/06 10:24 AM, "Constantine Tsardounis" <[hidden email]>
wrote:

> 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])))
> }

 mylist <- list()
 for (i in list.files('.',pattern='.R')) {
   mylist[[i]] <- read.csv(i)
 }

Sean

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html