oldval<-c("1012","1014","1015","N0","N0(i-)","N0(i+)","N0(mol-)","N0(mol+)","N1","N1a","N1b","N1c","N1mi","N1NOS","N2a",
"N2b","N2NOS","N3a","N3b","N3c","N3NOS","NX")
newval<-factor(c("NX","NX","NX","N0","N0","N0","N0","N0","N1","N1","N1","N1","N1","N1","N2","N2","N2","N3","N3","N3","N3","NX"))
primary.site.breast2010.4$Nnode<-newval[match(primary.site.breast2010.4$Derived.AJCC.N..7th.ed..2010.2015.,oldval)]
##primary.site.breast2010.4$Derived.AJCC.N..7th.ed..2010.2015.需要整理的分类变量
##oldval 是primary.site.breast2010.4$Derived.AJCC.N..7th.ed..2010.2015.里面有多少分类,列出来
第二种方法
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="M0"]<-"M0"
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="M0(i+)"]<-"M0"
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="M1"]<-"M1"
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="161"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="17"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="312"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="438"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="442"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="465"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="521"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="568"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="824"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="825"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="827"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="841"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="97"]<-"MX"
primary.site.breast2010.4$metastasis<-factor(primary.site.breast2010.4$metastasis)
table(primary.site.breast2010.4$metastasis)
table(primary.site.breast2010.4$CS.mets.at.dx..2004.2015.)
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="M0"]<-"M0"
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="M0(i+)"]<-"M0"
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="M1"]<-"M1"
primary.site.breast2010.4$metastasis[primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="161"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="17"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="312"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="438"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="442"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="465"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="521"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="568"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="824"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="825"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="827"|primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="841"|
primary.site.breast2010.4$Derived.AJCC.M..7th.ed..2010.2015.=="97"]<-"MX"
primary.site.breast2010.4$metastasis<-factor(primary.site.breast2010.4$metastasis) #转换成因子
新建一列:primary.site.breast2010.4$metastasis
第三种
xx<-c(0.1,2,3,4,5,6,8,9,10,56)
xy<-cut(xx,breaks = c(0,2,6,Inf))
xy##发现划分时,都是小于等于
primary.site.breast2010.4$tumorsize<-cut(primary.site.breast2010.4$CS.tumor.size..2004.2015.,
breaks = c(-1,0,19,49,989,990,992,995,999),labels = c("no","small","medium","large","unknow",
"small","medium","unknow"))
##第四种
library(plyr)
forest_before_psm_os$age<-revalue(forest_before_psm_os$age,c("<41"=1,"41-60"=2,"61-80"=3,">80"=4))