Hi all, this is a reoccurring theme in my programming and I need some help
with it.  When I use a built in function and need to use it on a subset of
my data frame, I always end up using the subset function first, but this
seems very clunky.  For example, if I have years 2003:2013 with season "a"
and "b" within each year, and I want to create a smooth.spline, I end up
creating a subset for each year and season, and then have a smooth spline
function for each year and season.  Can I do this more efficiently?


The subsets are below:


size.2003<-subset(size,Year==2003&Season=="a")

size.2004<-subset(size,Year==2004&Season=="a")

size.2005<-subset(size,Year==2005&Season=="a")

size.2006<-subset(size,Year==2006&Season=="a")

size.2007<-subset(size,Year==2007&Season=="a")

size.2008<-subset(size,Year==2008&Season=="a")

size.2009<-subset(size,Year==2009&Season=="a")

size.2010<-subset(size,Year==2010&Season=="a")

size.2011<-subset(size,Year==2011&Season=="a")

size.2012<-subset(size,Year==2012&Season=="a")

size.2013<-subset(size,Year==2013&Season=="a")

size.2003b<-subset(size,Year==2003&Season=="b")

size.2004b<-subset(size,Year==2004&Season=="b")

size.2005b<-subset(size,Year==2005&Season=="b")

size.2006b<-subset(size,Year==2006&Season=="b")

size.2007b<-subset(size,Year==2007&Season=="b")

size.2008b<-subset(size,Year==2008&Season=="b")

size.2009b<-subset(size,Year==2009&Season=="b")

size.2010b<-subset(size,Year==2010&Season=="b")

size.2011b<-subset(size,Year==2011&Season=="b")

size.2012b<-subset(size,Year==2012&Season=="b")

size.2013b<-subset(size,Year==2013&Season=="b")

The smooth.spline is below

2003<-with(size.2003,smooth.spline(Size,Prop,spar=0.25))

2004<-with(size.2004,smooth.spline(Size,Prop,spar=0.25))
2005<-with(size.2005,smooth.spline(Size,Prop,spar=0.25))
etc. etc.

M. Keith Cox, Ph.D.
Principal
MKConsulting
17105 Glacier Hwy
Juneau, AK 99801
U.S. 907.957.4606

        [[alternative HTML version deleted]]

______________________________________________
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