在进行文章的撰写时,总是少不了一些表格的绘制,当然最标准的表格就是三线表了。我一般用word绘制三线表,但是R语言也可以且比较省时间。
代码语言:javascript复制setwd('D:\SCIwork\F4\clinical')
require(table1)
rm(list=ls())
library(dplyr)
library(tidyr)
data <- read.csv('survival.csv', header = T, row.names = 1)
library(stringr)
colnames(data)
data <- data[-(1:6), ]
data$T <- str_extract(data$TNM, "T\d")
data$Te1 <- str_extract(data$TNM, "T\d[a-z] ")
data$Te1 <- ifelse(is.na(data$Te1),data$Te2,data$Te1)
data$N <- str_extract(data$TNM, "N\d")
data$N <- str_extract(data$N, "\d")
data$M <- str_extract(data$TNM, "M\d")
data$M <- str_extract(data$M, "\d")
data$stage1 <- str_trim(str_extract(data$Stage, "\s[H-Z] "),
side = c("both", "left", "right"))
data$stage <- ifelse(data$stage1 == "X" ,'', data$stage1)
data$stage
colnames(data)
data$Age <- ifelse(data$Age > 60, '> 60','<= 60')
table(data$Age)
table(data$OS)
## 对我们感兴趣的变量因子化
data$OS <-
factor(data$OS,
levels=c(0,1),
labels=c("Alive", # 第一个作为参考组
"Death"))
table <- table1(~ factor(Gender) factor(Age) factor(stage)
factor(T) factor(N) factor(M) | OS, data=data)
table