ActWt Rkey
133 R01
131 R01
131 R01
130 R01
128 R01
125 R01
128 R02
133 R02
132 R02
132 R02
130 R02
133 R03
123 R03
122 R03
117 R03
I would like to calculate mean value of ActWt by Rkey, and then construct a new column and put the mean value by that particular Rkey ID... result should look like this: (i just make up the mean value to illustrate how I want to put them...
ActWt Rkey Mean
133 R01 130
131 R01 130
131 R01 130
130 R01 130
128 R01 130
125 R01 130
128 R02 131
133 R02 131
132 R02 131
132 R02 131
130 R02 131
I tried dplyr package in R...but not sure how to match the mean value back according to Rkey.. Many thanks!!
We need to use
mutate
after grouping by 'Rkey'