【发布时间】:2013-11-07 14:31:03
【问题描述】:
如何从数据框中选择特定列中值大于 1 的行?
这就是我的数据的样子:
> dput(head(tbl_comp[,-1]))
structure(list(Meve_mean = c(7774.44229552491, 43374.1166119026,
585562.72426545, 3866.54724117546, 320338.197537275, 918368.01990607
), Mmor_mean = c(39113.5325249635, 119476.157216344, 1296530.34384725,
23511.2980313616, 209092.538981888, 577355.581852083), Mtot_mean = c(23443.9874102442,
81425.1369141232, 941046.53405635, 13688.9226362685, 264715.368259581,
747861.800879077), tot_meanMe = c(258492586.999527, NA, NA, NA,
NA, NA), tot_meanMm = c(246665241.110832, NA, NA, NA, NA, NA),
tot_sdMe = c(35569170.0311164, NA, NA, NA, NA, NA), tot_sdMm = c(30522099.9189256,
NA, NA, NA, NA, NA), Wteve_mean = c(10752.4381084666, 53658.8435672746,
715547.921685567, 3422.17220367207, 335384.199178456, 1013708.18845339
), Wtmor_mean = c(29254.6414790837, 98804.8007431987, 1001344.20496027,
11541.8862121394, 217110.411645861, 571826.157099177), Wttot_mean = c(18681.9538387311,
73007.110928385, 838032.04308901, 6902.04963587237, 284695.433093058,
824330.175015869), tot_meanwte = c(278901499.672313, NA,
NA, NA, NA, NA), tot_meanwtm = c(235415566.775308, NA, NA,
NA, NA, NA), tot_sdwte = c(16743477.4011497, NA, NA, NA,
NA, NA), tot_sdwtm = c(3922418.43271348, NA, NA, NA, NA,
NA), diff_eve = c(0.72303994843767, 0.808331185101342, 0.818341730189196,
1.12985174650959, 0.955138012828161, 0.905949098928778),
diff_mor = c(1.33700262752933, 1.20921408998001, 1.29478988086689,
2.03704122525771, 0.963070068343606, 1.00966976533735), diff_tot = c(1.25490018938172,
1.11530419268331, 1.12292428650774, 1.98331269093204, 0.929819510568173,
0.907235745512628)), .Names = c("Meve_mean", "Mmor_mean",
"Mtot_mean", "tot_meanMe", "tot_meanMm", "tot_sdMe", "tot_sdMm",
"Wteve_mean", "Wtmor_mean", "Wttot_mean", "tot_meanwte", "tot_meanwtm",
"tot_sdwte", "tot_sdwtm", "diff_eve", "diff_mor", "diff_tot"), row.names = c(NA,
6L), class = "data.frame")
在此数据中,我最感兴趣的三列:
diff_eve diff_mor diff_tot
0.7230399 1.3370026 1.2549002
0.8083312 1.2092141 1.1153042
0.8183417 1.2947899 1.1229243
1.1298517 2.0370412 1.9833127
0.9551380 0.9630701 0.9298195
0.9059491 1.0096698 0.9072357
我想创建由每一列中的值选择的新数据框。应该有 6 个新的数据帧。 “diff_eve”列中低于 1 的值应该在新数据帧中,高于 1 = 下一个数据帧的值也是如此。当然,我想保留数据中的所有列(tbl_comp)。
让我展示新数据框的示例。通过 diff_eve 列中低于 1 的值进行选择:
>newdata.frame
diff_eve diff_mor diff_tot .. ....... ..... rest of the columns from tbl_comp.
0.7230399 1.3370026 1.2549002
0.8083312 1.2092141 1.1153042
0.8183417 1.2947899 1.1229243
0.9551380 0.9630701 0.9298195
0.9059491 1.0096698 0.9072357
我希望你们中的一些人理解我想要实现的目标。
【问题讨论】:
-
您的六个数据集是
diff_eve、diff_mor、diff_tot列的各自值过滤为小于一和大于一吗? -
抱歉回复晚了,但我不得不去实验室。