R 拆分包含多个因素的输出列表
假设我有三个向量:R 拆分包含多个因素的输出列表,r,split,R,Split,假设我有三个向量: time <- c(306,455,1010,210,883,1022,310,361,218,166) status <- c(0,1,0,1,0,0,1,0,1,1) gender <- c("Male","Male","Female","Male","Male","Male","Female","Female","Female","Female") 我的问题是,有没有办法将输出分成男性和女性。例如: output_Female <- ?????
time <- c(306,455,1010,210,883,1022,310,361,218,166)
status <- c(0,1,0,1,0,0,1,0,1,1)
gender <- c("Male","Male","Female","Male","Male","Male","Female","Female","Female","Female")
我的问题是,有没有办法将输出分成男性和女性。例如:
output_Female <- ?????
output_Female
output_Female
time n.risk n.event survival std.err lower 95% CI upper 95% CI
166 5 1 0.8 0.179 0.516 1
218 4 1 0.6 0.219 0.293 1
310 3 1 0.4 0.219 0.137 1
361 2 0 0.4 0.219 0.137 1
1010 1 0 0.4 0.219 0.137 1
output_Male <- ?????
output_Male
output_Male
time n.risk n.event survival std.err lower 95% CI upper 95% CI
166 5 1 0.8 0.179 0.516 1
218 4 1 0.6 0.219 0.293 1
310 3 1 0.4 0.219 0.137 1
361 2 0 0.4 0.219 0.137 1
1010 1 0 0.4 0.219 0.137 1
output\u Female这里有一个使用tidy
library(broom)
library(dplyr)
tidy(A, censored = TRUE) %>%
split(.$strata)
或使用base R
txt <- capture.output(summary(A, censored = TRUE))
ind <- cumsum(grepl("gender=", txt))
lst <- lapply(split(txt[ind >0], ind[ind >0]), function(x)
read.table(text = x[-(1:2)], header = FALSE))
nm1 <- scan(text= gsub("\\s+[0-9]|%\\s+", ".", txt[4]), quiet = TRUE, what = "")
lst <- lapply(lst, setNames, nm1)
txt
library(broom)
library(dplyr)
tidy(A, censored = TRUE) %>%
split(.$strata)
txt <- capture.output(summary(A, censored = TRUE))
ind <- cumsum(grepl("gender=", txt))
lst <- lapply(split(txt[ind >0], ind[ind >0]), function(x)
read.table(text = x[-(1:2)], header = FALSE))
nm1 <- scan(text= gsub("\\s+[0-9]|%\\s+", ".", txt[4]), quiet = TRUE, what = "")
lst <- lapply(lst, setNames, nm1)