各位老师,刚刚开始学习R 不久,遇到这么一个问题,代码运行老是报错,不知道错误出在哪里,以下是程序:
uni_cox_in_bulk <- function(gene_list, survival_info_df){
uni_cox <- function(single_gene){
formula <- as.formula(paste('Surv(PFS, PFS_status)~', single_gene))
surv_uni_cox <- summary(coxph(formula, data = df))
ph_hypothesis_p <- cox.zph(coxph(formula, data = df))$table[1,3]
if (surv_uni_cox$coefficients[,5]<0.05 & ph_hypothesis_p>0.05){ #get the pvalue
single_cox_report <- data.frame('uni_cox_sig_genes'=single_gene,
'beta'=surv_uni_cox$coefficients[,1],
'Hazard_Ratio'=exp(surv_uni_cox$coefficients[,1]),
'z_pvalue'=surv_uni_cox$coefficients[,5],
'Wald_pvalue'=as.numeric(surv_uni_cox$waldtest[3]),
'Likelihood_pvalue'=as.numeric(surv_uni_cox$logtest[3]))
single_cox_report
}
}
uni_cox_list <- lapply(gene_list, uni_cox)
do.call(rbind, uni_cox_list)
}
uni_cox_df <- uni_cox_in_bulk(gene_list = gene_list, survival_info_df = df)
运行后报错为:Error in asgn[[ii]] : subscript out of bounds
请问哪位前辈知道这是错在哪里吗?非常感谢!