行和错误(Qf):&x27;x';必须是至少两个维度的数组(msm::msm2surv)

行和错误(Qf):&x27;x';必须是至少两个维度的数组(msm::msm2surv),r,syntax-error,survival-analysis,R,Syntax Error,Survival Analysis,我正在msm包中使用函数msm2surv,并尝试将纵向数据转换为flexsurve包喜欢的格式。下面是我的示例tmp tmp <- structure(list(id = c(89, 90, 90, 91, 91, 91, 92, 92, 93, 93, 94, 94, 94, 95, 95, 96), days = c(9157, 0, 9156, 0, 8394, 9156, 0, 9156, 0, 8079, 0, 8933, 9003, 0, 8430, 0), event =

我正在msm包中使用函数msm2surv,并尝试将纵向数据转换为flexsurve包喜欢的格式。下面是我的示例tmp

tmp <- structure(list(id = c(89, 90, 90, 91, 91, 91, 92, 92, 93, 93, 
94, 94, 94, 95, 95, 96), days = c(9157, 0, 9156, 0, 8394, 9156, 
0, 9156, 0, 8079, 0, 8933, 9003, 0, 8430, 0), event = c(1, 1, 
1, 1, 2, 2, 1, 1, 1, 5, 1, 3, 6, 1, 4, 1)), row.names = c(NA, 
-16L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "id", drop = TRUE, indices = list(
    0L, 1:2, 3:5, 6:7, 8:9, 10:12, 13:14, 15L), group_sizes = c(1L, 
2L, 3L, 2L, 2L, 3L, 2L, 1L), biggest_group_size = 3L, labels = structure(list(
    id = c(89, 90, 91, 92, 93, 94, 95, 96)), row.names = c(NA, 
-8L), class = "data.frame", vars = "id", drop = TRUE, .Names = "id"), .Names = c("id", 
"days", "event"))

tmp我们可以将
tbl_df
转换为
data.frame
,它应该可以工作

out <- msm2Surv(data=as.data.frame(tmp), subject="id",
               time="days", state="event", Q=Q)
dim(out)
#[1] 31  8
out
out <- msm2Surv(data=as.data.frame(tmp), subject="id",
               time="days", state="event", Q=Q)
dim(out)
#[1] 31  8