按多个值过滤列 [英] Filtering Column by Multiple values

查看:46
本文介绍了按多个值过滤列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据一个包含多个值的列来过滤值.

I would like to filter values based on one column with multiple values.

例如,一个 data.frame 具有s& p 500 标记,我必须选择其中的 20 个以及相关的收盘价.怎么做?

For example, one data.frame has s&p 500 tickers, i have to pick 20 of them and associated closing prices. How to do it?

推荐答案

如果我很了解您的问题,我相信您应该使用 dplyr :

If I understand well you question, I believe you should do it with dplyr:

library(dplyr)
target <- c("Ticker1", "Ticker2", "Ticker3")
filter(df, Ticker %in% target)

答案可在 https://stackoverflow.com/a/25647535/9513536 中找到

干杯!

这篇关于按多个值过滤列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆