Dplyr Data manipulation Data filtering (filter)

Source: Internet
Author: User

In the use of R we almost do not open Hadley Wickham developed a few packages, the previous said Ggplot2, Reshape2, and will be talking about DPLYR

Because these packages can easily make us escape from complex data operations, the operation process is concise, and most importantly, the data results are also very concise.

First, let's take a look at the first function filter ()

Filter (. Data, ...)

The parameter is simple, only data, that is, the object to manipulate, and the other is the data operation condition.

Let's look at some simple examples

Library (DPLYR) x<-data.frame (Id=1:6,              name=c ("Wang", "Zhang", "Li", "Chen", "Zhao", "song"),              shuxue=c ( 89,85,68,79,96,53),              yuwen=c (77,68,86,87,92,63))
Dim (x) #查看数据行列属性

[1] 6 4

X

Filter (x,name== "Zhang")

Filter (X,SHUXUE>60,YUWEN<90)

Multiple conditional filters can be made, and conditions can be separated by commas

Filter (X,SHUXUE>80|YUWEN<80)

Multi-conditional filtering, or you can use connectors & or | To connect.

In contrast, filter () is relatively simple, the use of the process is mainly to see the degree of flexibility of individuals.

  

Dplyr Data manipulation Data filtering (filter)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.