当前位置:网站首页>Missing value handling
Missing value handling
2022-06-22 17:37:00 【R language enthusiasts】
List of articles
Preface
In daily statistical analysis , Missing data is a common phenomenon , The data may be missing in a data entry , Or you don't get the result you want in the Q & A , Will cause partial loss of data . There are many ways to deal with missing data , We need to solve it according to the actual situation . When the proportion of missing data in the whole is relatively small , We can delete , But if the data has a significant impact on the results , Then we cannot delete , The data needs to be filled .
1、 Detection of missing values ?
stay R In language , The sign of our missing value is NA To represent the , And in R in , Use functions is.na() It can be used to detect whether there are missing values in the data .
na <- c(2,2,NA,6,8)
is.na(na)
result :
Use is.na() Function to determine if there is a missing value , The returned result is a logical value , That is, with or without missing values . When the returned logical value is FALSE There is no missing value , When the return value is TURE Is the missing value .
2、NaN Detection of
NaN Represents a value that cannot be represented , The value of uncertainty , It can be used is.nan() To detect
nan <- c(5,Inf,5,NaN,6)
is.nan(nan)
result 
3、 Processing of missing values
Borrow and reissue :
new_na <- c(1,1,2,3,NA,7,8)
new_na[is.na(new_na)] <- mean(new_na,na.rm=T)
result

4、 Select a number that is not a missing value
Add a missing value in the data , Then we cannot calculate , So we need to filter the missing values to calculate . Then we just need to select a number that is not a missing value .
new_nas <- c(1,NA,1,2,3,NA,7,8)
new_nas <- new_nas[!is.na(new_nas)]
result :
5、 Matrix with missing values
The matrix can always have missing values , But the same can not be calculated , We need to deal with the missing values before we can calculate .
mat <- matrix(c(1:11,NA),nr=3,nc=4,byrow = T)
result 
6、 Not a missing value
mean(mat,na.rm=T)
result 
7、 Delete the line
When we delete NA The row where the value is located , There are no missing values in the matrix , So this matrix can be calculated .
newmat <- na.omit(mat)
result 
8、 Calculating mean
We find a mean value of the number in the matrix , You can get the following results .
mean(newmat)
result 
summary
1:is.na() Missing values can be detected , And return the logical vector ;
2:is.nan() It can detect NaN value , And return the logical vector ;
3: Those with missing values cannot be calculated .
边栏推荐
- Figure operation flow of HAMA BSP Model
- Apache ShardingSphere 一文读懂
- Stop automatically after MySQL server starts
- System throughput, TPS (QPS), user concurrency, performance test concepts and formulas
- Recommend 7 super easy-to-use terminal tools - ssh+ftp
- Blazor University (30)表单 —— 从 InputBase 派生
- [Alibaba cloud server - install MySQL version 5.6 and reinstall]
- 内容推荐流程
- Xftp 7 (ftp/sftp client) v7.0.0107 official Chinese free official version (with file + installation tutorial)
- STM32系列(HAL库)——F103C8T6硬件SPI点亮带字库OLED屏
猜你喜欢

每秒處理10萬高並發訂單的樂視集團支付系統架構分享

WPF效果第一百九十篇之再耍ListBox

Xftp 7 (ftp/sftp client) v7.0.0107 official Chinese free official version (with file + installation tutorial)

JMeter use case

Blazor University (31)表单 —— 验证

UI自动化定位利器-xpath实战

Qt筆記-QMap自定義鍵(key)

Quickly master asp Net authentication framework identity - user registration
![[face recognition] matlab simulation of face recognition based on googlenet deep learning network](/img/e8/050ca85542ccbf1402b84c5dbf6f5e.png)
[face recognition] matlab simulation of face recognition based on googlenet deep learning network

网传学习通1.7亿密码泄露!有什么补救措施?
随机推荐
The principle of locality in big talk
Some difficulties in making web pages
Mybaits:接口代理方式实现Dao
AD20/Altium designer——过孔盖油
Come to Xiamen! Online communication quota free registration
有同学问PHP要学什么框架?
synchronized实现原理
System throughput, TPS (QPS), user concurrency, performance test concepts and formulas
.NET 发布和支持计划介绍
Is the CSC securities account given by qiniu school true? Is it safe to open an account
How can the new generation of HTAP databases be reshaped in the cloud? Tidb V6 online conference will be announced soon!
[fpga+pwm] design and implementation of phase shift trigger circuit for three-phase PWM rectifier based on FPGA
imx6ull的GPIO操作方法
How to do well in R & D efficiency measurement and index selection
redis. clients. jedis. exceptions. JedisDataException ERR invalid password.
Redis实现延迟队列的正确姿势
Service or mapper cannot be injected into a multithread
Is flush easy to open an account? Is it safe to open an account online?
Description of new features and changes in ABP Framework version 5.3.0
快速掌握 ASP.NET 身份认证框架 Identity - 用户注册