I have a data frame (sample below), as follows:
df = structure(list(Stage1yBefore = c("3.1", "1", "4", "2", "NA"),
Stage2yBefore = c("NA", "2", "3.2", "2", "NA"), ClinicalActivity1yBefore =
c(TRUE,
TRUE, TRUE, TRUE, FALSE), ClinicalActivity2yBefore = c(FALSE,
TRUE, TRUE, TRUE, FALSE)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -5L))
I would like to convert it to a long format using dplyr, but for some reason get an error.
The output should look like (converting the first row of df):
Output = data_frame(TimeFrame = c("1y", "2y"), Stage = c(3, NA), Clinical =
c(T, F))
So that each row of df becomes 2 rows in the output.
What I tried doesnt work (and I'm actually not sure exactly how to do this):
Output = gather(df, TimeFrame, Stage, Clinical, Stage1yBefore:ClinicalActivity2yBefore)
I get:
Error in .f(.x[[i]],...): Object 'Clinical' not found.
Any ideas?