One way to plot subsets of data identified by a grouping variable is to use
lapply() on a list of subsets.  The approach is worth mentioning because
similar tactics are useful for many problems. 

#List of unique values for grouping variable
#that is not necessarily a factor
names <- as.list(unique(df$Experiment))

#List of dataframes; 1 for each unique value of grouping variable
df.lst <- lapply(names,function(name)subset(df,Experiment==name))

#Name components of the list
#Not necessary in this case... but permits indexing by level
#of the grouping variable
names(df.lst) <- names

#Now you can use lapply() to carry out the same operation on
#each component of your list.  For example, to send plots to
#a pdf with 1 page for each component:

pdf("plot.pdf")
lapply(df.lst,function(df)plot(df[,2],df[,3]))
dev.off() 




-----
Glen Sargeant
Research Wildlife Biologist
-- 
View this message in context: 
http://n4.nabble.com/Mutliple-sets-of-data-in-one-dataset-Need-a-loop-tp1018503p1018714.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.

Reply via email to