基于行值的子集列 [英] Subset columns based on row value
本文介绍了基于行值的子集列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个简单的问题,但我一直找不到任何答案.假设您有一个包含具有分子特征的 n 列的数据框.在每列的最后一行,表示方差系数.
This may be a simple question, but I haven't been able to find any answer. Consider you have a dataframe with n columns with molecular features. In the last row of each column, a coefficient of variance is expressed.
示例数据集:
a <- data.frame(matrix(runif(30),ncol=3))
b <- c(50.23,45.23,21)
a<-rbind(a,b)
X1 X2 X3
1 0.1097075 0.78584027 0.20925033
2 0.6081752 0.39669748 0.65559913
3 0.9912855 0.68462073 0.54741795
4 0.8543848 0.53776889 0.43789447
5 0.2579654 0.92188090 0.61292895
6 0.6203840 0.73152279 0.82866311
7 0.6643195 0.84953926 0.62192976
8 0.5760624 0.30949900 0.11032929
9 0.8888167 0.04530598 0.08089825
10 0.8926815 0.61736284 0.19834310
11 50.2300000 45.23000000 21.00000000
如何进行子集化,以便仅在最后一行中获得 CV>50 的列?所以我的新 data.frame 将是:
How do I subset so I only get the columns with CV>50 in the last row? So my new data.frame would be:
X1
1 0.1097075
2 0.6081752
3 0.9912855
4 0.8543848
5 0.2579654
6 0.6203840
7 0.6643195
8 0.5760624
9 0.8888167
10 0.8926815
11 50.230000
推荐答案
我们可以做到
a[,a[nrow(a),]>50,drop=FALSE]
这篇关于基于行值的子集列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文