[R] Multiple plots via sapply or lapply?

From: Antje <niederlein-rstat_at_yahoo.de>
Date: Sun 07 Jan 2007 - 17:11:27 GMT


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@stat.math.ethz.ch mailing list

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. Received on Mon Jan 08 04:15:14 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 07 Jan 2007 - 19:31:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.