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
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
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
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
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
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
6 matches
Mail list logo