[R] group by function

Ragia Ibrahim ragia11 at hotmail.com
Sat Nov 7 15:32:12 CET 2015


Dear group,
kindly, I have the following data frame

structure(c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 
3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1.5, 2, 1, 0, 2, 2, 1.5, 
0, 0, 1, 1, 2, 0, 1, 2), .Dim = c(15L, 3L), .Dimnames = list(
    NULL, c("i", "Measure_id", "value")))



it has 3 coulmns
I used 
    df$newcoulmn <-  ave(df$value, paste( df$i, df$Measure_id), FUN= function(x)   x/max(x) )


to get x /max(x) and calc probability.. but I want to do that for each source measure_id" separately  that means that rows 4,7,13 ..their value should be divided by 1.5 not 2..

rows 1,5,11 will be divided by  2 the max of their same group grouped by measure id 
 how to make such grouping

thanks in advance
Ragia 		 	   		  
	[[alternative HTML version deleted]]



More information about the R-help mailing list