如何仅从阈值开始删除列中的值?

时间:2019-09-21 18:27:37

标签: r dataframe

我有一个数据帧(k x 4)。我已经按降序排列了四列之一(假设从19到-9)。我想丢掉那些小于1.5的值。

我只是尝试了以下代码的各种组合失败

subset(w, select = -c(columnofinterest, <=1.50))

有人可以帮助我吗?

非常感谢!

1 个答案:

答案 0 :(得分:2)

您可以使用arrange软件包中的filterdplyr

library(dplyr)
w <- data.frame(use_this = round(runif(100, min = -9, max = 19)),
                 second = runif(100),
                 third = runif(100),
                 fourth = runif(100)) %>% 
  arrange(desc(use_this)) %>% 
  filter(use_this >= 1.5)

输出:

> w
   use_this      second      third     fourth
1        19 0.264306555 0.11234097 0.30149863
2        19 0.574675520 0.50406805 0.71502833
3        19 0.376586752 0.21530618 0.35323250
4        18 0.949974135 0.46726122 0.36008741
5        17 0.339737597 0.11358402 0.04035303
6        16 0.180291264 0.81855913 0.16109650
7        16 0.958398058 0.94827266 0.54693974
8        16 0.297317238 0.28726682 0.63560208
9        16 0.653006870 0.15175848 0.69305851
10       16 0.685338886 0.30493976 0.89360112
11       16 0.493931093 0.52830391 0.68391458
12       16 0.945083084 0.19880501 0.66769341
13       16 0.910927578 0.86032225 0.73062990
14       15 0.662130980 0.19207451 0.44240610
15       15 0.730482762 0.92418574 0.46387086
16       15 0.547101759 0.87847767 0.27973739
17       15 0.487773258 0.05870471 0.40147753
18       15 0.695824922 0.91289504 0.94897518
19       14 0.576095914 0.42914670 0.27707368
20       14 0.156691824 0.02187951 0.31940887
21       13 0.079037019 0.16993999 0.53232350
22       13 0.944372064 0.63485350 0.23548337
23       13 0.016378244 0.42772076 0.76618218
24       13 0.606340182 0.33611591 0.36017352
25       13 0.170346203 0.43325314 0.16285515
26       13 0.605379012 0.95574187 0.23941377
27       12 0.157352454 0.90963650 0.01611328
28       12 0.353934785 0.80058806 0.13782414
29       12 0.464950823 0.81835421 0.12771521
30       12 0.624139506 0.69472154 0.02833191
31       11 0.362033514 0.98849181 0.37684822
32       11 0.067974815 0.24154922 0.49300890
33       11 0.522271380 0.03502680 0.50665790
34       10 0.810183210 0.56598130 0.41279787
35       10 0.609560713 0.46745813 0.34939724
36       10 0.087748839 0.56531646 0.02249387
37       10 0.008262635 0.68432285 0.35648525
38       10 0.757824842 0.57826099 0.89973902
39       10 0.428174539 0.12538288 0.69233083
40       10 0.785175550 0.21516237 0.36578714
41       10 0.631388832 0.63700087 0.40933640
42       10 0.171396873 0.37925970 0.27935731
43       10 0.773437320 0.24710107 0.23902388
44        8 0.443778088 0.77238651 0.08517639
45        8 0.954302451 0.87102748 0.52031446
46        8 0.347608835 0.79912385 0.36169856
47        8 0.839238717 0.54200177 0.52221408
48        8 0.235710838 0.85575923 0.78092366
49        7 0.610772265 0.16833538 0.94704562
50        7 0.242917834 0.02852729 0.87131760
51        7 0.875879507 0.04537683 0.81000861
52        7 0.577880660 0.54259171 0.43301336
53        6 0.541772984 0.06164861 0.62867700
54        6 0.071746509 0.51758874 0.70365933
55        5 0.103953563 0.99147043 0.33944620
56        5 0.504618656 0.95827073 0.65527417
57        5 0.726648637 0.37460291 0.47072657
58        5 0.796268586 0.09644167 0.93960812
59        5 0.796498528 0.68346948 0.23290885
60        5 0.490859592 0.76727730 0.39888256
61        5 0.949232913 0.02954981 0.56672834
62        4 0.360401806 0.62879833 0.31107107
63        4 0.926329930 0.87624801 0.91260914
64        4 0.922783983 0.11524112 0.06240194
65        3 0.518727534 0.23927630 0.37114683
66        3 0.951288192 0.58672287 0.45337659
67        3 0.767943126 0.76102957 0.24347122
68        2 0.786254279 0.39824869 0.58548193
69        2 0.321557042 0.75393236 0.43273743
70        2 0.872124621 0.89918160 0.55623725
71        2 0.242389529 0.85453423 0.78540085
72        2 0.013294874 0.61593974 0.70549476