2021-02-12 快速將多分類變量進行整合成幾個分類

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) #轉(zhuǎn)換成因子

新建一列: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##發(fā)現(xiàn)劃分時,都是小于等于

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))

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末嗅定,一起剝皮案震驚了整個濱河市自娩,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌渠退,老刑警劉巖忙迁,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件脐彩,死亡現(xiàn)場離奇詭異,居然都是意外死亡姊扔,警方通過查閱死者的電腦和手機惠奸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來恰梢,“玉大人佛南,你說我怎么就攤上這事∏堆裕” “怎么了嗅回?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長摧茴。 經(jīng)常有香客問我妈拌,道長,這世上最難降的妖魔是什么蓬蝶? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任尘分,我火速辦了婚禮,結(jié)果婚禮上丸氛,老公的妹妹穿的比我還像新娘培愁。我一直安慰自己,他們只是感情好缓窜,可當我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布定续。 她就那樣靜靜地躺著,像睡著了一般禾锤。 火紅的嫁衣襯著肌膚如雪私股。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天恩掷,我揣著相機與錄音倡鲸,去河邊找鬼。 笑死黄娘,一個胖子當著我的面吹牛峭状,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播逼争,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼优床,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了誓焦?” 一聲冷哼從身側(cè)響起胆敞,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后移层,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體启摄,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年幽钢,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片傅是。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡匪燕,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出喧笔,到底是詐尸還是另有隱情帽驯,我是刑警寧澤,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布书闸,位于F島的核電站尼变,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏浆劲。R本人自食惡果不足惜嫌术,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望牌借。 院中可真熱鬧度气,春花似錦、人聲如沸膨报。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽现柠。三九已至院领,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間够吩,已是汗流浹背比然。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留周循,地道東北人谈秫。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像鱼鼓,于是被迫代替她去往敵國和親拟烫。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容