Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个矩阵,每一行和每一列都有维度名称。
然后如何根据其特定的维度名称提取矩阵的一部分?例如,如果维度名称中包含某些特定字符串,则提取观察值。
谢谢!
我假设您熟悉[并且您遇到的唯一困难是找到与特定模式匹配的行名。你需要使用grep. 这是我选择包含“North”的行的示例:
[
grep
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