根據(jù)邏輯條件過濾數(shù)據(jù)。我想從data.frame基于邏輯條件。假設(shè)我有數(shù)據(jù)框架,就像 expr_value cell_type1 5.345618 bj fibroblast2 5.195871 bj fibroblast3 5.247274 bj fibroblast4 5.929771 hesc5 5.873096 hesc6 5.665857 hesc7 6.791656 hips8 7.133673 hips9 7.574058 hips10 7.208041 hips11 7.402100 hips12 7.167792 hips13 7.156971 hips14 7.197543 hips15 7.035404 hips16 7.269474 hips17 6.715059 hips18 7.434339 hips19 6.997586 hips20 7.619770 hips21 7.490749 hips我想要的是獲得一個新的數(shù)據(jù)框架,它看起來相同,但只有一個單元格類型的數(shù)據(jù)。例如:包含單元格類型“hESC”的子集/選擇行: expr_value cell_type1 5.929771 hesc2 5.873096 hesc3 5.665857 hesc或者細(xì)胞型“Bj成纖維細(xì)胞”或“hESC”: expr_value cell_type1 5.345618 bj fibroblast2 5.195871 bj fibroblast3 5.247274 bj fibroblast4 5.929771 hesc5 5.873096 hesc6 5.665857 hesc有什么簡單的方法嗎?我試過:expr[expr[2] == 'hesc']# [1] "5.929771" "5.873096" "5.665857" "hesc" "hesc" "hesc" 如果原始數(shù)據(jù)框架被稱為“Exr”,但是它以錯誤的格式給出了結(jié)果,正如您所看到的。
3 回答

至尊寶的傳說
TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個贊
==
:
expr[expr$cell_type == "hesc", ]
%in%
:
expr[expr$cell_type %in% c("hesc", "bj fibroblast"), ]

嗶嗶one
TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個贊
subset
subset(expr, cell_type == "hesc")subset(expr, cell_type %in% c("bj fibroblast", "hesc"))
dplyr::filter()
filter(expr, cell_type %in% c("bj fibroblast", "hesc"))

陪伴而非守候
TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個贊
expr[expr[2] == 'hesc']
x[y]
x[y,]
> expr[expr[2] == 'hesc',] expr_value cell_type4 5.929771 hesc5 5.873096 hesc6 5.665857 hesc
- 3 回答
- 0 關(guān)注
- 751 瀏覽
添加回答
舉報(bào)
0/150
提交
取消