您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)如何利用subset針對數(shù)據(jù)框按照條件進(jìn)行判斷和篩選數(shù)據(jù)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
利用subset從數(shù)據(jù)框中選擇符合條件的數(shù)據(jù)
subset(x, ...)
x表示一個待篩選data frame
例如有如下數(shù)據(jù):
> dat Samples group treatment Time 1 GSM1625995 con6h control 6h 2 GSM1625996 con6h control 6h 3 GSM1625997 con6h control 6h 4 GSM1625998 con12h control 12h 5 GSM1625999 con12h control 12h 6 GSM1626000 con12h control 12h 7 GSM1626001 con24h control 24h 8 GSM1626002 con24h control 24h 9 GSM1626003 con24h control 24h 10 GSM1626004 hm6h treat 6h 11 GSM1626005 hm6h treat 6h 12 GSM1626006 hm6h treat 6h 13 GSM1626007 hm12h treat 12h 14 GSM1626008 hm12h treat 12h 15 GSM1626009 hm12h treat 12h 16 GSM1626010 hm24h treat 24h 17 GSM1626011 hm24h treat 24h 18 GSM1626012 hm24h treat 24h
一個選擇條件:選擇數(shù)據(jù)框中所有con6h的數(shù)據(jù)(group列)
> con6h = subset(dat,group == "con6h") > con6h Samples group treatment Time 1 GSM1625995 con6h control 6h 2 GSM1625996 con6h control 6h 3 GSM1625997 con6h control 6h >
多條件選擇:選擇control 且24h(按照treatment 和Time列)
> con24h = subset(dat,treatment== "control" & Time == "24h") > con24h Samples group treatment Time 7 GSM1626001 con24h control 24h 8 GSM1626002 con24h control 24h 9 GSM1626003 con24h control 24h
判斷后提取指定的區(qū)域
> con24h = subset(dat,treatment== "control" & Time == "24h",select = c("Samples","group")) > con24h Samples group 7 GSM1626001 con24h 8 GSM1626002 con24h 9 GSM1626003 con24h
感謝各位的閱讀!關(guān)于“如何利用subset針對數(shù)據(jù)框按照條件進(jìn)行判斷和篩選數(shù)據(jù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。