Try this:

foo <- function(x, dir = getwd(), ...){
    png(file.path(dir, sprintf("%s.png", x)))
    plot(DF.split[[x]], ...)
    dev.off()
}


DF.split <- split(DF[, c("year", "peak")], DF$site)

sapply(DF.split, foo)

On Fri, Aug 7, 2009 at 4:05 PM, Ingrid Tohver <itohver@u.washington.edu>wrote:

> Hello,
> I am attempting to create several plots based on "site" (~300 total) and am
> having trouble with the code. I simply want to create a plot using the code,
> plot(year, peak), for the following dataset. I would like for each site to
> be plotted on a separate page and the plots saved in a directory. Would a
> "foreach" loop work? I tried a "by" statement, but it doesn't seem to work
> with plotting functions.
> I would really appreciate any leads.
> Ingrid
>
>  site          year   peak
> ALBEN       5  101529.6
> ALBEN      10  117483.4
> ALBEN      20  132960.9
> ALBEN      50  153251.2
> ALBEN     100  168647.8
> ALBEN     200  184153.6
> ALBEN     500  204866.5
> ALDER       5    6561.3
> ALDER      10    7897.1
> ALDER      20    9208.1
> ALDER      50   10949.3
> ALDER     100   12287.6
> ALDER     200   13650.2
> ALDER     500   15493.6
> AMERI       5   43656.5
> AMERI      10   51475.3
> AMERI      20   58854.4
> AMERI      50   68233.3
> AMERI     100   75135.9
> AMERI     200   81908.3
>
>
> Ingrid M Tohver
> Research Scientist, Climate Impacts Group
> University of Washington
>
> ______________________________________________
> R-help@r-project.org 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


