0

I have a dataframe looking like this:

code    tst   wek tmp  
a      7.56     1 T1   
a      8.36     2 T1   
a      9.17     1 T1   
a      7.84     2 T2   
a      8.65     1 T2   
a      8.39     2 T2   
a      7.56     1 T3   
a      7.9      2 T3   
a      8.1      2 T3   
b      6.9      1 T1   
b      7.89     1 T1   
b      7.88     2 T1   
b      8.23     1 T2   
b      7.28     2 T2   
b      7.17     2 T2   
b      7.33     2 T3   
b      7.4      1 T3   
b      6.79     2 T3 

I want to calculate a variable that gives me the mean of the variable "tst" for each person by wek and tmp. This means that for example the mean for person with the code "a" would have the same value in the rows with wek = 1 and tmp = 1.

I hope this is clear enough. I know that the aggregate function does calculating mean by groups, but what I have found so far did not fit for my issues. Since this answer

considers one group only and furthermore, the duplicated names were dropped in this example. I want to keep the rows with duplicated codes since the rows contain other variables as well.

psycho95
  • 111
  • 7

0 Answers0