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

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

问题描述

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

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

install.packages('LearnBayes')

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

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',]

阅读来自?subset

这是一个旨在交互使用的便利功能.为了编程最好使用标准的子集功能,如‘[’,特别是参数的非标准评估子集"可能会产生意想不到的后果.

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天全站免登陆