利用subset从数据框中选择符合条件的数据
subset(x, ...)
x表示一个待筛选data frame
例如有如下数据:
> 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
一个选择条件:选择数据框中所有con6h的数据(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
判断后提取指定的区域
> con24h = subset(dat,treatment== "control" & Time == "24h",select = c("Samples","group"))
> con24h
Samples group
7 GSM1626001 con24h
8 GSM1626002 con24h
9 GSM1626003 con24h
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!