通过列中的值过滤数据帧 [英] Filtering a data frame by values in a column

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

问题描述

我正在使用数据集 LearnBayes 。对于那些想要查看实际数据的人:

I am working with the dataset LearnBayes. For those that want to see the actual data:

install.packages('LearnBayes')

我试图根据列中的值过滤掉行。例如,如果列值为water,那么我想要该行。如果列值为牛奶,那么我不想要它。最终,我试图过滤掉所有饮料列的人都是水。

I am trying to filter out rows based on the value in the columns. For example, if the column value is "water", then I want that row. If the column value is "milk", then I don't want it. Ultimately, I am trying to filter out all individuals who's Drink column is "water".

推荐答案

子命令不是必需的。只需使用数据框架索引

The subset command is not necessary. Just use data frame indexing

studentdata[studentdata$Drink == 'water',]

?子集


这是一个方便的函数,用于交互式使用。对于
编程,最好使用标准子集功能,如
'[',特别是参数
'子集'的非标准评估可能会产生意想不到的后果。

This is a convenience function intended for use interactively. For programming it is better to use the standard subsetting functions like ‘[’, and in particular the non-standard evaluation of argument ‘subset’ can have unanticipated consequences.

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

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