我有一个数据框(示例如下),如下:
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))
我想使用 dplyr 将其转换为长格式,但由于某种原因出现错误。
输出应如下所示(转换 df 的第一行):
Output = data_frame(TimeFrame = c("1y", "2y"), Stage = c(3, NA), Clinical =
c(T, F))
这样 df 的每一行在输出中变成 2 行。
我尝试过的不起作用(实际上我不确定该怎么做):
Output = gather(df, TimeFrame, Stage, Clinical, Stage1yBefore:ClinicalActivity2yBefore)
我得到:
Error in .f(.x[[i]],...): Object 'Clinical' not found.
有任何想法吗?