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

From: Joshua Wiley <>
Date: Fri, 25 Jun 2010 16:21:35 -0700

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.


Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 25 Jun 2010 - 23:25:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jun 2010 - 23:50:36 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive