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

2010-06-25 Thread Joshua Wiley
On Fri, Jun 25, 2010 at 5:24 PM, Joris Meys wrote: > Just want to add that if you want to clean out the NA rows in a matrix > or data frame, take a look at ?complete.cases. Can be handy to use > with big datasets. I got curious, so I just ran the codes given here > on a big dataset, before and aft

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

2010-06-25 Thread Joris Meys
Just want to add that if you want to clean out the NA rows in a matrix or data frame, take a look at ?complete.cases. Can be handy to use with big datasets. I got curious, so I just ran the codes given here on a big dataset, before and after removing NA rows. I have to be honest, this is surely an

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

2010-06-25 Thread Joshua Wiley
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

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

2010-06-25 Thread Joshua Wiley
Hello Eric, I am not sure how your need to use list() will fit in with this, but for your sample data, this will do the trick. matrix(rowMeans(DF, na.rm=TRUE), ncol=1) HTH, Josh On Fri, Jun 25, 2010 at 4:08 PM, emorway wrote: > > Forum, > > Using the following data: > > DF<-read.table(textCon

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

2010-06-25 Thread Phil Spector
Eric - What you're describing is taking the mean of each row while ignoring missing values: apply(DF,1,mean,na.rm=TRUE) [1] 22.60NaNNaNNaNNaNNaNNaNNaN 102.00 19.20 [11] 19.20NaNNaNNaN 11.80 7.62NaNNaNNaNNaN [21]NaN 75.00N

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

2010-06-25 Thread emorway
Forum, Using the following data: DF<-read.table(textConnection("A B 22.60 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 102.00 NA 19.20 NA 19.20 NA NA NA NA NA NA NA 11.80 NA 7.62 NA NA NA NA NA NA NA NA NA NA NA 75.00 NA NA NA 18.30 18.2 NA NA NA NA 8.44 NA 18.00 NA N