Hi Everyone,
I have a dataframe as provided below
Group=c(1, 1, 1, 2 ,2, 3 ,3, 3 ,3, 3, 4 ,4, 4, 4, 4,4,4, 5, 5 ,5)
Temp= c(0 ,0.1, 0.2, 0 ,0.1, 0 ,0.2 ,0.1, 0 ,0.1, 0, 0.1, 0.5, 0.1 ,0.1, 0, 0.1, 0, 0.1, 0.1)
DF = cbind(Group,Temp)
I want to create a new group in such a way that it sums the DF for the first 5 rows.
The expected output is
Group_new=c(1, 1, 1, 2 ,2, 3 ,3, 3 ,3, 3, 4 ,4, 4, 4, 4,5, 5 ,6,6,6)
Temp_sum=c(0.3, 0.3 ,0.3, 0.1 ,0.1, 0.4 ,0.4, 0.4 ,0.4, 0.4, 0.9, 0.9, 0.9,
0.9, 0.9 ,0.1, 0.1, 0.2 ,0.2, 0.2)
Df1 = cbind(Group_new,Temp,Temp_sum)
Thanks in advance.!