All u guys are really great. I am just encolsing the
summary of all the replies I have recieved for the
request for applying Tapply for the Dataframe
tapply(col4,list(col1,col2),mean)[tapply(col4,list(col1,col2))]
# A great method for vectorizing the o/p
fac <- interaction(dat[1:2],drop=T)
cbind(dat,mean=tapply(dat$col4,fac,mean)[fac])
# Another great method - basically same method as
above
lm(col4 ~ col1:col2, data=data.frame)$res
# The Difference vector between the mean and the
# original data
Special thanks to Bert Gunter, Nick Ellis, Peter
Alspach, Remy van de Ven.
If any one needs the complete information can contact
me directly. Thanks again for all your help.
-----Original Message-----
From: Mandans [mailto:mandans_p@yahoo.com]
Sent: Wednesday, April 11, 2001 3:20 PM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Using Tapply for Dataframe.
Hi.all
First and foremost let me thank all..For the quick
correspondance for my earlier mail. U guys are really
great.
If I can I have another question. I am using S-plus
4.5 on Windows NT and have a data frame with couple of
columns.
# data frame
#col1 col2 col3 col4
A Type1 25 0.8
A Type2 30 0.1
A Type1 40 12
B Type3 24 1.8
B Type1 22 1.8
C Type1 21 1.8
D Type2 18 1.5
I applied tapply for getting mean of the each class
and type for the first two columns.
tapply(col4,list(col1,col2),mean)
and I need to compare the indvidual values in the
dataframe with the coressponding, class and type mean
value(Output from tapply). I use loop to go through
each value and do the mean calculation and then use
that mean value to compare with the individual value.
It becomes slow if I have many rows. I was wondering
anyone knows any better method.
And again thanks a lot for all your help
Joepaul
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
|