[R] can this be simplified with purrr:map or mapply?

Brandon Payne payneb at post.bgu.ac.il
Wed Jan 18 10:57:10 CET 2017


I can't get my head around the *apply family of functions,
surely there's a better way than what I have.
I've tried using paste0 on the years, but then I have lists of strings, not
data frames.

`realList<-paste0("exp",as.character(2004:2014),"s")`

I can't seem to convert these lists of strings to references to data frames.

years<-c(2004:2014)
framesEXP<-list(exp2004s,exp2005s,exp2006s,exp2007s,exp2008s,exp2009s,exp2011s,exp2010s,exp2012s,exp2013s,exp2014s)

framesFAM<-list(fam2004s,fam2005s,fam2006s,fam2007s,fam2008s,fam2009s,fam2011s,fam2010s,fam2012s,fam2013s,fam2014s)

data2004<<-merge(exp2004s,fam2004s, by="HHNUM")
data2005<<-merge(exp2005s,fam2005s, by="HHNUM")
data2006<<-merge(exp2006s,fam2006s, by="HHNUM")
data2007<<-merge(exp2007s,fam2007s, by="HHNUM")
data2008<<-merge(exp2008s,fam2008s, by="HHNUM")
data2009<<-merge(exp2009s,fam2009s, by="HHNUM")
data2010<<-merge(exp2010s,fam2010s, by="HHNUM")
data2011<<-merge(exp2011s,fam2011s, by="HHNUM")
data2012<<-merge(exp2012s,fam2012s, by="HHNUM")
data2013<<-merge(exp2013s,fam2013s, by="HHNUM")
data2014<<-merge(exp2014s,fam2014s, by="HHNUM")

dput(data2004, file="../dataframes/data2004.txt")
dput(data2005, file="../dataframes/data2005.txt")
dput(data2006, file="../dataframes/data2006.txt")
dput(data2007, file="../dataframes/data2007.txt")
dput(data2008, file="../dataframes/data2008.txt")
dput(data2009, file="../dataframes/data2009.txt")
dput(data2010, file="../dataframes/data2010.txt")
dput(data2011, file="../dataframes/data2011.txt")
dput(data2012, file="../dataframes/data2012.txt")
dput(data2013, file="../dataframes/data2013.txt")
dput(data2014, file="../dataframes/data2014.txt")

	[[alternative HTML version deleted]]



More information about the R-help mailing list