

Hi,

I have a very big data frame and I would like to apply a function to one of the columns within different groups  and obtain another dataframe
My data frame is like this:

group var1 var2 myvar 
group1 1 a 100 
group2 2 b 200 
group2 34 c 300 
group3 5 d 400 
group3 6 e 500 
group4 7 f 600 

and I woud like to apply this function to column myvar: 

mifunc = function(vec) {
vec=as.vector(vec)
for (i in 1:(length(vec)-1)){
vec[i]=vec[i+1]-1
}
return(vec)
}
by the groups in column group. I would like to obtain the same dataframe but with f(myvar) instead of myvar.

How can I do this?

Thanks, 
Estefania
	[[alternative HTML version deleted]]

