[R] tapply

Jim Brennan jfbrennan at rogers.com
Tue Jun 21 01:42:04 CEST 2005


This may help
R>wei
     V1           V2   V3
1  5540 389100307391 2600
2  5541 389100307391 2600
3  5542 389100307391 2600
4  5543 389100307391 2600
5  5544 389100307391 2600
6  5546 381300302513   NA
7  5547 387000307470   NA
8  5548 387000307470   NA
9  5549 387000307470   NA
10 5550 387000307470   NA
11 5551 387000307470   NA
12 5552 387000307470   NA
R>ave(wei[,3],wei[,2],FUN=sum)
 [1] 13000 13000 13000 13000 13000    NA    NA    NA    NA    NA    NA    NA
R>

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Weiwei Shi
Sent: June 20, 2005 7:16 PM
To: R-help at stat.math.ethz.ch
Subject: [R] tapply

hi,
i have another question on tapply:
i have a dataset z like this:
5540 389100307391      2600
5541 389100307391      2600
5542 389100307391      2600
5543 389100307391      2600
5544 389100307391      2600
5546 381300302513        NA
5547 387000307470        NA
5548 387000307470        NA
5549 387000307470        NA
5550 387000307470        NA
5551 387000307470        NA
5552 387000307470        NA

I want to sum the column 3 by column 2.
I removed NA by calling:
tapply(z[[3]], z[[2]], sum, na.rm=T)
but it does not work.

then, i used
z1<-z[!is.na(z[[3]],]
and repeat
still doesn't work.

please help.

-- 
Weiwei Shi, Ph.D

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list