RUser
RUser

Reputation: 598

Creating a matrix subset in R

I have a VERY BIG single row matrix (n=20000):

V1  Col1 Col2 Col3 ... Coln
ABC 1    3    5        2

I want to subset this to only keep columns with a value >= 3:

V1  Col2 Col3
ABC 3    5  

I have searched everywhere but cannot come up with a proper solution. I suppose I can transpose it, subset and then transpose back?
Any help will be greatly appreciated.

Upvotes: 0

Views: 89

Answers (1)

IRTFM
IRTFM

Reputation: 263332

Logical indexing works on either the i or j arguments to "["

Mtx[ , Mtx > 3] # ...............

Read and study ?[ carefully. There is so much power in that function that it generally takes about 10 readings to gather all of its capacities and subtleties. (This may eve work on a dataframe of the appropriate construction and the workings of "[" are quite similar for those two structure=types.

Upvotes: 1

Related Questions