gixser11 gixser11 -4 years ago 53
R Question

R aggregation of columns by met condition in one column

I am trying to aggregate or associate 2 columns in a 4 column matrix. The matrix is filled with numeric values. I would like to show only column1 and column3 when column1 is >.25. I have tried numerous R commands but can't get the 2 columns to show when the criteria is met in column 1.
For example

1.094262, 14
0.5962845, 17


Below is the dataset. Example of desired output above.

0.1287953 3 12 1

1.094262 13 14 3

0.5962845 8 17 4

0.6511204 7 19 5

0.2533915 4 6 2

0.8222555 6 18 6

0.08695875 3 7 1

0.6096232 6 6 2

1.583204 24 7 1

0.08337463 4 7 1

0.06398186 1 11 2

0.2713974 4 11 2

0.6205648 13 4 1

1.276595 15 14 3

Answer Source

Is this what you are looking for?

df[df$V1>0.25,c(1,3)]
          V1 V3
2  1.0942620 14
3  0.5962845 17
4  0.6511204 19
5  0.2533915  6
6  0.8222555 18
8  0.6096232  6
9  1.5832040  7
12 0.2713974 11
13 0.6205648  4
14 1.2765950 14

where df is:

df=read.table(text="0.1287953   3   12  1
1.094262    13  14  3
0.5962845   8   17  4
0.6511204   7   19  5
0.2533915   4   6   2
0.8222555   6   18  6
0.08695875  3   7   1
0.6096232   6   6   2
1.583204    24  7   1
0.08337463  4   7   1
0.06398186  1   11  2
0.2713974   4   11  2
0.6205648   13  4   1
1.276595    15  14  3", h=F)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download