Entering edit mode
3.4 years ago
mbk0asis
▴
700
I'd like to divide the values of t2~t4
by t1
in each group in R from the data like below.
group type value
A t1 10
A t2 20
A t3 30
A t4 40
B t1 20
B t2 40
B t3 60
B t4 80
I tried to un-melt by type
but I think there would be better way to do it.
Any ideas?
Thank you!
Wow! That's exactly what I wanted.
Thnak you!!
Dunois,
I have another question.
If I want to add a column containing number of members in each group, how can I do it?
Here you go:
Also, please note, the code snippets I provided are using uni-directional pipes (
%>%
). So these chains do not store the output you see at the terminal. To store the output, point the entire chain at a new variable like so (for example):Or, if you just want to update
df
itself with the new columns and whatnot, use a bi-directional pipe as the first operator in the chain like so:(Just wanted to mention this in case you weren't aware of this, and ended up wondering why your results are wrong much later.)
Thank you again for your kind answers!
You're welcome!!