[R] Multiple plots via sapply or lapply?

Antje niederlein-rstat at yahoo.de
Sun Jan 7 18:11:27 CET 2007


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



More information about the R-help mailing list