r - 使用特定行中的值过滤 R 中的列
问题描述
我必须根据行的特定值对数据框进行子集化。这意味着如果包含大于 10 的值的行必须用作标准,以提取该行中满足条件的所有列。
这是我的数据样本。
structure(list(`Copper ores and concentrates; copper mattes, cemen` = c(200.53,
274.84, 1.37, 376.686907694609), `Fabrics, woven, of man-made fabrics` = c(4093.12,
1184.47, 0.29, 342.762777758776), Copper = c(44.76, 91.45, 2.04,
186.843219392315), Zinc = c(80.14, 110.73, 1.38, 152.996417519341
), `Waste, parings and scrap, of plastics` = c(590.3, 286.3,
0.49, 138.857682534305), `Fixed vegetable fats & oils, crude, refined, fract.` = c(864.14,
344.63, 0.4, 137.44281817761), `Sulphur and unroasted iron pyrites` = c(23.99,
55.11, 2.3, 126.599087119633), `Radio-actives and associated materials` = c(48.59,
76.67, 1.58, 120.977338958633), `Rails & railway track construction mat., iron, steel` = c(464.66,
214.76, 0.46, 99.259367279301), `Iron ore and concentrates` = c(46.91,
67.8, 1.45, 97.9927520784481), `Crude vegetable materials, n.e.s.` = c(164.46,
123.26, 0.75, 92.3812939316551), `Other plastics, in primary forms` = c(187.76,
124.21, 0.66, 82.169386983383), `Crude animal materials, n.e.s.` = c(43.08,
56.52, 1.31, 74.1529805013928), `Pig iron & spiegeleisen, sponge iron, powder & granu` = c(17.17,
33.03, 1.92, 63.5399475829936), `Ores and concentrates of base metals, n.e.s.` = c(15.7,
27.6, 1.76, 48.5197452229299), `Furskins, tanned or dressed, excluding those of 8483` = c(178.49,
75.12, 0.42, 31.6152972155303), `Metalworking machinery (excludingmachine-tools) & parts` = c(179.18,
71.69, 0.4, 28.6832018082375)), row.names = c("SD", "Mean", "INTENSITY",
"INTENSITY2"), class = "data.frame")
我希望数据框必须将自身限制为在名为的行中大于 10 的值INTENSITY2
.
我试过这个 tf4[, tf4[,"INTENSITY2" > 10, ]]
,但它不起作用。
解决方案
这也有效。
tf4[,unname(apply(tf4['INTENSITY2',],1,function(x) which(x>10)))]
推荐阅读
- jquery - 如何在表中使用追加方法
- c# - 复制共享点文件夹错误,说明文件夹无效
- python - 如何在 Python Plotnine barplot 中更改 y 轴以显示百分比 (%)?
- scala - 如何说服 Scala.js 使用 Javascript 定义的方法 equals 进行比较?
- javascript - 进度条未设置正确的宽度
- c++ - C++14:2 个随机生成器 - 一个有效,另一个无效
- php - 从 Woocommerce 中可变产品的变体中获取产品属性标签
- xml - 如何通过abap中的XSLT程序读取XML文件的属性
- javascript - 动态创建的选择不绑定到它们的可观察值?
- c - 从http请求中提取号码