apology for re sending the Email, I changed the format to plain text as I have 
been advised
the data  is as follow  

thanks Sarah, 
I used pdut, and here is the data as written on R..I attached the dput result
structure(list(Measure_id = c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 
3, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 
3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3), i = c(5, 5, 
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
7, 7, 7, 7), j = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), id = c(1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 
9, 10, 11, 12), value = c(2, 1.5, 0, 0, 1, 0.5, 0, 0, 0, 0, 0.5, 
2, 2, 1.5, 0, 1, 2, 0, 0.5, 1.44269504088896, 0, 0, 0, 0, 1, 
1.5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 0, 
0, 0, 0)), .Names = c("Measure_id", "i", "j", "id", "value"), row.names = c(NA, 
48L), class = "data.frame")

the data  is as follow  :

   Measure_id i j id value
1           1 5 1  1   2.0
2           1 5 2  1   2.0
3           1 5 1  2   1.5
4           1 5 2  2   1.5
5           1 5 1  3   0.0
6           1 5 2  3   0.0
7           1 5 1  4   0.0
8           1 5 2  4   1.0
9           1 5 1  5   1.0
10          1 5 2  5   2.0
..        ... . . ..   ...
I want to add a probability column,  the prob column depends on id grouped by 
for each i
the rank will be current (value / max value ) for the same id for specific i, 
it would be

 Measure_id i j id value    prob
1           1 5 1  1   2.0          2/2  
2           1 5 2  1   2.0          2/2  
3           1 5 1  2   1.5          1.5/1.5   
4           1 5 2  2   1.5          1.5/1.5 
5           1 5 1  3   0.0          0
6           1 5 2  3   0.0          0
7           1 5 1  4   0.0          0/1  
8           1 5 2  4   1.0          1/1  
9           1 5 1  5   1.0          1/2
10          1 5 2  5   2.0          2/3
..        ... . . ..   ...

then I want to add a rank column that rank regarding probability, if the 
probability equal they took the same rank for the
same id belongs to the same i, otherwize lower probability took higher rank for 
examole if we have three values for i=7 and for the three values the id is 1 
and the probability is ( .2,.4,.5) the rank should be 3,2,1



I looked at aggregate and dplyr...should I use for loop and subset each i and 
id rows do calculations and then group them again ??
is there easier way?

replying  highly appreciated
> 
> 
> 
>> Date: Sun, 6 Sep 2015 19:02:02 -0400 
>> Subject: Re: [R] groups Rank 
>> From: sarah.gos...@gmail.com 
>> To: ragi...@hotmail.com 
>> CC: r-help@r-project.org 
>> 
>> Please use dput() to provide data, rather than expecting people to 
>> open random attachments. Besides, there are multiple options for 
>> getting data into R, and we need to know exactly what you did. dput() 
>> is faster and easier. 
>> 
>> What have you tried? Did you look at aggregate() as I suggested? 
>> 
>> Sarah 
>> 
>> On Sat, Sep 5, 2015 at 10:44 AM, Ragia Ibrahim <ragi...@hotmail.com> wrote: 
>>> thanks for replying, I attached the data frame 
>>> for source "i" I want to sum the values and get the max value then add a 
>>> new column called rank . That new column cell value for each source i and 
>>> for specific id would be (value/max value) * count of rows that have the 
>>> same criteria "same i and same id" 
>>> 
>>> many thanks 
>>> Ragia 
>>> 
>>>> Date: Fri, 4 Sep 2015 10:19:35 -0400 
>>>> Subject: Re: [R] groups Rank 
>>>> From: sarah.gos...@gmail.com 
>>>> To: ragi...@hotmail.com 
>>>> CC: r-help@r-project.org 
>>>> 
>>>> Hi Ragia, 
>>>> 
>>>> I can't make out your data or desired result, but it sounds like 
>>>> aggregate() might get you started. If you need more help, please 
>>>> repost your data using dput() and do NOT post in HTML so that we can 
>>>> see what your desired result looks like. 
>>>> 
>>>> Sarah 
>>>> 
>>>> On Fri, Sep 4, 2015 at 10:12 AM, Ragia Ibrahim <ragi...@hotmail.com> 
>>>> wrote: 
>>>>> Dear Group,kinldy, I have the following data frame df 
>>>>> id value1 1 4 2 1 4 3 1 6 4 1 6 5 2 1.5 6 2 2.5 7 2 2.5 8 2 2.5 
>>>>> 
>>>>> add rank column regarding id coulmn where rank for the highest value 
>>>>> would be 1, others rank would be the (value/ value of heighest)/ 
> number of 
>>>>> rows that took the same value 
>>>>> thus the data frame should be 
>>>>> id value Rank1 1 4 0.332 1 4 0.333 1 6 0.54 1 6 0.55 2 1.5 0.6 6 2 2.5 
>>>>> 0.337 2 2.5 0.338 2 2.5 0.33 
>>>>> 
>>>>> how to reach this resultthanks in advanceRagia 
>>>>> [[alternative HTML version deleted]] 
>>>>> 
                                          
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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