Reputation: 1084
I have a matrix, and there are dimensional names for each row and column.
How can I then extract a part of the matrix according to their specific dimension names? For example, extract an observation if the dimensional name contains some specific string in it.
Thanks!
Upvotes: 0
Views: 454
Reputation: 89057
I assume you are familiar with [
and that the only difficulty you have is to find row names that match a certain pattern. You need to use grep
. Here is an example where I select rows that contain "North":
USArrests[grep("North", rownames(USArrests)), ]
# Murder Assault UrbanPop Rape
# North Carolina 13.0 337 45 16.1
# North Dakota 0.8 45 44 7.3
Upvotes: 3