Sorry to bother you. I have a longitudinal dataset but it is in wide format.
There are 380 variables and over 3000 id's.
I am trying to turn the data into a long format so there is a time variable column.
The time variable is indicated by a suffix infront of each column variable so V0 is the Time at baseline and V01 is the time at 1 year. V02 is the time at second year. V03 is the time at 3 years etc.
Most of the variables are categorised using this time variable but not all. So v0pase is the pase at baseline. V01pase is the pase at 1 year.
Not all the variables have a time variable. Some are categorical e.g gender, depression etc.
I am trying to reshape it into a long format in R however my code does not appear to work:
The database is called "TrialData"
TrialDataLong <- reshape(TrialData, varying = c((grepl("v",))), direction = "long",
timevar = "visit/year", idvar =
"id", sep = "v")
I have linked an image of a snapshot of the old data to what I am aiming for.
I would be grateful if someone can be kind enough to assist in this. I am fairly newish to R.
Many thanks in advance.
Best wishes James