Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] Multiple plots via sapply or lapply?

niederlein rstat

2007-01-07

Replies:

Hi all,

I've got the following problem. I have a vector containing file names. I
want to read these files as csv and calculate the density-function for
each file (has just one column with data). Then, I'd like to plot all
density functions into one window. I did the following to calculate the
density data:

s <- sapply(filelist, function(x) {
   if(file.exists(x))
   {
     file <- read.csv(x, sep="\t", header=F)
     return( list(density(file$V1)$x, density(file$V1)$y))
   }
 })

Now I would like to plot these x,y data in a similar way but my result
"s" is a matrix containing lists...

   File1.csv    File2.csv  File3.csv
[1,] Numeric,512  Numeric,512  Numeric,512
[2,] Numeric,512  Numeric,512  Numeric,512

Now I don't know how to handle the x,y values for each plot into an
sapply (or lapply, I don't know)

Any idea? Maybe, I should somehow change the return type?

Antje

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
©2008 r-help.com - Jax Systems, LLC, U.S.A.