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.
假设我有一个数据框'H',就像这样
C1 C2 a 1 b 1 c 2 d 3 e 4 f 4 g 5
和一个列表 X (as.factor) 去
"1" "2" "4"
使用 match 命令,
X2=H[match(X,H$C2),]
仅将 H 减少到三行,并且 X 的每个元素仅存在一个实例 (a,c,e)。我应该使用什么命令将 H 简化为 X 以使在 X 中找到的所有元素实例都存在(即简化表应包含 a、b、c、e、f)?
干杯。
> H[H$C2 %in% X,] C1 C2 1 a 1 2 b 1 3 c 2 5 e 4 6 f 4