Suppose that we have a data set including six variables and id variable like below:
id v2019 v2020 v2021 u2019 u2020 u2021
In this case, if we use Stata we can make this long form very easily using the "reshape" command like below.
reshape long v u, i(id) j(year)
=> id v u
But, when I use the gather function in tidyr package, this function makes just three columns every time.
data %>% gather(key = "key, value = "value")
=> id key value
that is gather function gathers "every" columb with out seperate of different variables suchs as u and v.
So my question is that how can I imitate the function of reshape in stata using gather in r.
thank you for your time spent to read this question.
question from:
https://stackoverflow.com/questions/66047913/from-wide-form-to-long-form-using-gather-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…