Hello, I have a matrix with 6 columns and 12 rows. I want to extract out those IDs (rownames) from my matrix which have a negative values. For each ID(row) if the negative value is even under 1 column it needs to be extracted out. I will be grateful for any correct suggestion. Thanks Manisha Here is the matrix that I am working on: ID A B C D E F 1 -4.18972 -3.8946 -1.14888 -1.88406 -8.34124 10.97497 2 11.81028 11.1054 0.85112 0.115942 -4.34124 24.97497 3 -0.18972 -1.8946 1.85112 -4.88406 -17.3412 -13.025 4 -1.18972 3.105402 -0.14888 -12.8841 -15.3412 4.974967 6 -3.18972 4.105402 24.85112 0.115942 1.658762 -11.025 7 -2.18972 -10.8946 -20.1489 -1.88406 3.658762 -11.025 8 -0.18972 -7.8946 -7.14888 -9.88406 3.658762 -9.02503 9 -5.18972 -4.8946 -12.1489 0.115942 -12.3412 10.97497 10 17.81028 9.105402 -15.1489 10.11594 19.65876 9.974967 11 538.8103 335.1054 863.8511 229.1159 520.6588 143.975 12 30.81028 18.1054 30.85112 16.11594 9.658762 13.97497 [[alternative HTML version deleted]]
rownames(X)[apply(X, 1, function(r) any(r < 0))]
... if I understand you correctly.
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On
Behalf Of Manisha Brahmachary [mb3058 at c2b2.columbia.edu]
Sent: 07 June 2009 08:54
To: r-help at r-project.org
Subject: [R] extract rows having negative values
Hello,
I have a matrix with 6 columns and 12 rows. I want to extract out those IDs
(rownames) from my matrix which have a negative values. For each ID(row) if
the negative value is even under 1 column it needs to be extracted out. I
will be grateful for any correct suggestion.
Thanks
Manisha
Here is the matrix that I am working on:
ID
A
B
C
D
E
F
1
-4.18972
-3.8946
-1.14888
-1.88406
-8.34124
10.97497
2
11.81028
11.1054
0.85112
0.115942
-4.34124
24.97497
3
-0.18972
-1.8946
1.85112
-4.88406
-17.3412
-13.025
4
-1.18972
3.105402
-0.14888
-12.8841
-15.3412
4.974967
6
-3.18972
4.105402
24.85112
0.115942
1.658762
-11.025
7
-2.18972
-10.8946
-20.1489
-1.88406
3.658762
-11.025
8
-0.18972
-7.8946
-7.14888
-9.88406
3.658762
-9.02503
9
-5.18972
-4.8946
-12.1489
0.115942
-12.3412
10.97497
10
17.81028
9.105402
-15.1489
10.11594
19.65876
9.974967
11
538.8103
335.1054
863.8511
229.1159
520.6588
143.975
12
30.81028
18.1054
30.85112
16.11594
9.658762
13.97497
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Thank you Bill, your suggestion works just fine!!!
-----Original Message-----
From: Bill.Venables at csiro.au [mailto:Bill.Venables at csiro.au]
Sent: Sunday, June 07, 2009 3:23 AM
To: Manisha Brahmachary; r-help at r-project.org
Subject: RE: extract rows having negative values
rownames(X)[apply(X, 1, function(r) any(r < 0))]
... if I understand you correctly.
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On
Behalf
Of Manisha Brahmachary [mb3058 at c2b2.columbia.edu]
Sent: 07 June 2009 08:54
To: r-help at r-project.org
Subject: [R] extract rows having negative values
Hello,
I have a matrix with 6 columns and 12 rows. I want to extract out those IDs
(rownames) from my matrix which have a negative values. For each ID(row) if
the negative value is even under 1 column it needs to be extracted out. I
will be grateful for any correct suggestion.
Thanks
Manisha
Here is the matrix that I am working on:
ID
A
B
C
D
E
F
1
-4.18972
-3.8946
-1.14888
-1.88406
-8.34124
10.97497
2
11.81028
11.1054
0.85112
0.115942
-4.34124
24.97497
3
-0.18972
-1.8946
1.85112
-4.88406
-17.3412
-13.025
4
-1.18972
3.105402
-0.14888
-12.8841
-15.3412
4.974967
6
-3.18972
4.105402
24.85112
0.115942
1.658762
-11.025
7
-2.18972
-10.8946
-20.1489
-1.88406
3.658762
-11.025
8
-0.18972
-7.8946
-7.14888
-9.88406
3.658762
-9.02503
9
-5.18972
-4.8946
-12.1489
0.115942
-12.3412
10.97497
10
17.81028
9.105402
-15.1489
10.11594
19.65876
9.974967
11
538.8103
335.1054
863.8511
229.1159
520.6588
143.975
12
30.81028
18.1054
30.85112
16.11594
9.658762
13.97497
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.