[R] Adding columns of Aggregates to existing dataframe

tonyxv tonyxv at gmail.com
Sun Jun 22 03:16:48 CEST 2008


Thanks. ave() is the exact function I was after.



tonyxv wrote:
> 
> Hello,
> I have a dataframe 
> 
> 
> ID1   ID2
> A1    B3
> A1    B4
> A1    B3
> A1    B3
> A2    B1
> A2    B1
> A2    B4
> A3    B2
> A3    B2
> A5    B1
> A5    B1
> A5    B6
> A5    B4
> A6    B2
> 
> 
> 
> I want to add extra columns to the dataframe CountID1 and CountID2 which
> is the actual count of values such as A1 etc
> ie
> 
> 
> 
> ID1   ID2    CountID1    CountID2
> A1    B3     4           3
> A1    B4     4           4
> A1    B3     4           3
> A1    B3     4           3
> A2    B1     3           4
> A2    B1     3           4
> A2    B4     3           3
> A3    B2     2           3
> A3    B2     2           3
> A5    B1     4           4
> A5    B1     4           4
> A5    B6     4           1
> A5    B4     4           4
> A6    B2     1           3
> 
> 
> I know this can be done by first creating temporary aggregate dataframes
> then merging with the original.
> Is there an easier way if i want to calculate many aggregates without
> having to merge many temp tables.
> 
> 
> Thanks.
> 

-- 
View this message in context: http://www.nabble.com/Adding-columns-of-Aggregates-to-existing-dataframe-tp18039838p18050190.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list