R實現excel分列統計

2021-09-26 10:54:35 字數 921 閱讀 1189

team1=grep("糖尿病",w)

team2=grep("痴呆",w)

team3=grep("腦血管病",w)

team4=grep("高血壓病",w)

team5=grep("冠心病",w)

team6=grep("高血脂症",w)

team7=grep("貧血",w)

team8=grep("其他",w)

tang[team1]=1

chidai[team2]=1

nao[team3]=1

xueya[team4]=1

guan[team5]=1

xuezhi[team6]=1

pinxue[team7]=1

qita[team8]=1

disease

fix(disease)

write.csv(disease,file = "disease.csv")

grep[pattern,x]
在x中搜尋pattern,返回值是匹配的下標。

我測試了一下,grep搜尋的物件x可以是單列矩陣和向量,對於資料框,必須轉化為矩陣。為保險起見,還是將先統一轉換為向量,再用grep匹配。

建立8個向量,不能用qita

excel分列怎麼操作?

excel分列怎麼操作?1 下面這一組日期就是我們要進行分列的內容,將其分成年 月 日。首先將這組日期選中。2 在excel選單中選擇資料,點選分列。3 在文字分列介面,我們選擇第一項分隔符號,點選下一步。4 在分隔符號中勾選其他,在其右側小框內輸入日期之間的小橫桿 繼續下一步。5 這個介面用來選擇...

R讀取excel檔案

一 使用軟體包xlsreadwrite library xlsreadwrite data read.xls choose.files d r rscript mydm wang2.xls 二 使用軟體包xlconnect library xlconnectjars library xlconnec...

R 讀取Excel資料

最簡單的是採用前兩種方式。1.將excel資料另存為csv格式,用read.csv 檔名 2.將excel資料另存為txt格式,用read.table 檔名 3.在windows系統中可以選擇使用rodbc軟體包中的相關函式來實現。library rodbc 載入rodbc軟體包 channel o...