[R] Average 2 Columns when possible, or return available value

Joshua Wiley jwiley.psych at gmail.com
Sat Jun 26 01:21:35 CEST 2010


btw, if you just wanted your exact code to work:

t(as.matrix(aggregate(t(as.matrix(DF)),list(rep(1:1,each=2)),mean,
na.rm=TRUE)[,-1]))

You will get NaNs rather than NAs where you are missing from both
rows, but that should not be a real issue.

<snip>

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list