In case it helps, this refers to the columns by position rather than name...
> aggregate(aDF[,4], by=aDF[,-4], sum)
It sums the fourth column (I'm guessing this is what Tammy meant by "merge") 
for unique combinations of all columns except the fourth.

It doesn't need the column names inside the aggregate, but does need the 
dataframe name. Because the dataframe name is specified inside the 
aggregate, we don't need the with().

HTH

Keith J

"Keith Jewell" <k.jew...@campden.co.uk> wrote in message 
news:gpoc8f$jl...@ger.gmane.org...
> Looks as if you copied my code without modifying to suit your data frame. 
> My data frame (aDF) had column names V1, V2, V3, V4
>> str(aDF)
> 'data.frame':   12 obs. of  4 variables:
> $ V1: chr  "2006-02-22 16:28:18" "2006-02-22 16:28:26" "2006-02-22 
> 16:28:28" "2006-02-22 16:28:31" ...
> $ V2: Factor w/ 4 levels "3","4","useractivity_act",..: 3 2 1 2 1 4 3 2 1 
> 2 ...
> $ V3: num  8 2 3 4 159 0 8 2 3 4 ...
> $ V4: num  0 0 0 1 0 0 0 0 0 0 ...
>
> ..so I referred to V1, V2, V3, V4 in the aggregate. We don't know the 
> column names in your data frame, which I guess is called act_data12. (By 
> the way, you told us almost nothing about your data frame. Consider 
> reading and following the posting guide.) What does
>> str(act_data12)
> produce?
>
> hth
>
> Keith J
> ==========================
> "Tammy Ma" <metal_lical...@live.com> wrote in message 
> news:bay0-dp1-6d9323fb68f77e4cfa77186...@phx.gbl...
>
> Thanks.
>
> Actually, I have been trying many time using method from KJ, There is 
> always the following information coming up or Rgui exit without reason.. I 
> have no idea about this?
>
> gh<-with(act_data12, aggregate(V4, by=list(V1,V2,V3), sum))
> Error in unlist(y, recursive = FALSE) :
>  promise already under evaluation: recursive default argument reference or 
> earlier problems?
>
> Tammy
>
>
>> Date: Tue, 17 Mar 2009 15:23:44 +0200
>> From: annette.heissw...@utu.fi
>> Subject: Re: [R] Merging
>> To: metal_lical...@live.com; r-help@r-project.org
>>
>> Tammy,
>>
>> You won't get more help if you post this again every half an hour... I 
>> don't quite understand what you exactly want to do, but it seemed at
>> least to me that Keith's suggestion (see again below) pretty much does 
>> what you want. If not, could you please specify *EXACTLY* what you
>> want to do. Thanks!
>>
>> Annette
>>
>> > From: Keith Jewell <k.jewell_at_campden.co.uk>
>> > Date: Tue, 17 Mar 2009 12:23:34 +0000
>> >
>> > Is this what you want it to do? (aDF is the original data frame)
>> >
>> >> aDF
>> >
>> >                     V1                V2  V3 V4
>> > 1  2006-02-22 16:28:18  useractivity_act   8  0
>> > 2  2006-02-22 16:28:26                 4   2  0
>> > 3  2006-02-22 16:28:28                 3   3  0
>> > 4  2006-02-22 16:28:31                 4   4  1
>> > 5  2006-02-22 16:28:35                 3 159  0
>> > 6  2006-02-22 16:31:14 useractivity_idle   0  0
>> > 7  2006-02-22 16:28:18  useractivity_act   8  0
>> > 8  2006-02-22 16:28:26                 4   2  0
>> > 9  2006-02-22 16:28:28                 3   3  0
>> > 10 2006-02-22 16:28:31                 4   4  0
>> > 11 2006-02-22 16:28:35                 3 159 25
>> >
>> > 12 2006-02-22 16:31:14 useractivity_idle 0 0
>> >> with(aDF, aggregate(V4, by=list(V1, V2, V3), sum))
>> >
>> >               Group.1           Group.2 Group.3  x
>> > 1 2006-02-22 16:31:14 useractivity_idle       0  0
>> > 2 2006-02-22 16:28:26                 4       2  0
>> > 3 2006-02-22 16:28:28                 3       3  0
>> > 4 2006-02-22 16:28:31                 4       4  1
>> > 5 2006-02-22 16:28:18  useractivity_act       8  0
>> > 6 2006-02-22 16:28:35                 3     159 25
>> >
>> >
>> > hth
>> >
>> > Keith J
>>
>>
>>
>>
>> Tammy Ma schrieb:
>> > I still couldn't solve it........any help would be preciated!
>> >
>> >
>> >
>> > Tammy
>> >
>> >
>> >
>> >
>> >
>> >> From: metal_lical...@live.com
>> >> To: r-help@r-project.org
>> >> Date: Tue, 17 Mar 2009 11:49:10 +0200
>> >> Subject: [R] Merging
>> >>
>> >>
>> >> Hi, All.
>> >>
>> >>
>> >> I have a data frame with the part as :
>> >>
>> >> .....
>> >> 142    2006-02-22 16:28:18  useractivity_act       8         0
>> >> 143    2006-02-22 16:28:26                 4            2         0
>> >> 144    2006-02-22 16:28:28                 3            3         0
>> >> 145    2006-02-22 16:28:31                 4            4         1
>> >> 146    2006-02-22 16:28:35                 3          159        0
>> >> 147    2006-02-22 16:31:14 useractivity_idle        0         0
>> >> 1421   2006-02-22 16:28:18  useractivity_act      8         0
>> >> 1431   2006-02-22 16:28:26                 4            2         0
>> >> 1441   2006-02-22 16:28:28                 3            3         0
>> >> 1451   2006-02-22 16:28:31                 4            4         0
>> >> 1461   2006-02-22 16:28:35                 3          159        25
>> >> 1471   2006-02-22 16:31:14 useractivity_idle        0         0
>> >> ....
>> >>
>> >> I want to merge the above as
>> >> 142    2006-02-22 16:28:18  useractivity_act       8         0
>> >>
>> >> 143    2006-02-22 16:28:26                 4            2         0
>> >>
>> >> 144    2006-02-22 16:28:28                 3            3         0
>> >>
>> >> 145    2006-02-22 16:28:31                 4            4         1
>> >>
>> >> 146    2006-02-22 16:28:35                 3          159       25
>> >>
>> >> 147    2006-02-22 16:31:14 useractivity_idle        0         0
>> >>
>> >> How should I do`??
>> >> Thanks.
>> >>
>> >> Tammy
>>
>> -- 
>> Annette Heisswolf
>> Section of Ecology
>> Department of Biology
>> University of Turku
>> 20014 Turku, Finland
>
> _________________________________________________________________
> Drag n' drop-Get easy photo sharing with Windows LiveT Photos.
>
> http://www.microsoft.com/windows/windowslive/products/photos.aspx
> [[alternative HTML version deleted]]
>
>
>
>
> --------------------------------------------------------------------------------
>
>
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to