Re: [R] Multiple plots via sapply or lapply?

From: talepanda <talepanda_at_gmail.com>
Date: Sun 07 Jan 2007 - 18:38:20 GMT

try apply() :

par(new=F);
apply(s,2,function(x){plot(x[[1]],x[[2]],type="o");par(new=T)})

On 1/8/07, Antje <niederlein-rstat@yahoo.de> wrote:
> 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.
>



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 05:42:47 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:42 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.