Using R to Fix Data Quality: Section 4

Section 4: Rule Checking


Overview

Sometimes, using some common sense to check the data is a good way to fix data quality problem. In R, there are some great features to help us checking rules conveniently. In this section, we are going to talk about how to check some rules in your data based on R.


Logical vector

Logical vector is a useful functionality in R. We can use some expressions to make logical vector directly. There is a good demo to show you how it works. We create a vector which includes several numbers. Then, we can make a logical vector to see how many numbers greater than 3 in this vector.

Create a number vector to be our test data:

> v=1:5
> v
[1] 1 2 3 4 5

Create the logical vector:

> grThree = v>3
> grThree
[1] FALSE FALSE FALSE  TRUE  TRUE

Check the number of TRUE:

> sum(grThree)
[1] 2
As can be seen, there are 2 numbers greater than 3 in vector v.

Show the numbers meet a condition:

> v[grThree]

[1] 4 5


Practice Question

1. Using weather.csv to be the data. How many values in Ozone are greater than 150? (using na.rm to delete NA)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值