In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to understand the missing values in R language. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can gain something after reading this article.
Most statistical methods assume that they are dealing with complete vectors, matrices, and data boxes, but in most cases, before dealing with real data, we have to eliminate missing value data: (1) delete instances containing missing values; (2) replace missing values with reasonable values. VIM and mice functions are mainly used to deal with missing values.
The VIM package provides mammalian data (sleep) to study whether sleep, biological variables and physical variables of 62 species of animals are independent variables or predictive variables.
Sleep variables include dreaming time (Dream), non-dreaming time (NonD) and their sum (Sleep). Physique variables include body weight (BodyWgt, in thousands), brain weight (BrainWgt, in units), longevity (Span, in years) and pregnancy (Gest, in days). Biological variables include the degree of predation (Pred), sleep exposure (Exp) and total risk (Danger) of species.
The way to deal with missing values:
In R language, NA is used to represent missing values, NaN (not a number) represents impossible values, symbols Inf and-Inf represent positive infinity and negative infinity, functions is.na, is.nan () and is.infinite () identify missing values, impossible values and infinite values, respectively, and the return result is TRUE or FALSE.
> install.packages (c ("VIM", "mice"))
Data (sleep,package= "VIM")
> sleep [complete.cases (sleep),] # list rows with no missing values
Ten thousand words are omitted here.
> sleep [complete.cases (sleep),]
BodyWgt BrainWgt NonD Dream Sleep Span Gest Pred Exp Danger
1 6654.000 5712.0 NA NA 3.3 38.6 645 3 5 3
3 3.385 44.5 NA NA 12.5 14.0 60 1 1 1
4 0.920 5.7 NA NA 16.5 NA 25 5 2 3
13 0.550 2.4 7.6 2.7 10.3 NA NA 2 1 2
14 187.100 419.0 NA NA 3.1 40.0 365 5 5 5
19 1.410 17.5 4.8 1.3 6.1 34.0 NA 1 2 1
20 60.000 81.0 12.0 6.1 18.1 7.0 NA 1 1 1
21 529.000 680.0 NA 0.3 NA 28.0 400 5 5 5
24 207.000 406.0 NA NA 12.0 39.3 252 1 4 1
26 36.330 119.5 NA NA 13.0 16.2 63 11 1
30 100.000 157.0 NA NA 10.8 22.4 100 1 1 1
31 35.000 56.0 NA NA NA 16.3 33 35 4
35 0.122 3.0 8.2 2.4 10.6 NA 30 2 1 1
36 1.350 8.1 8.4 2.8 11.2 NA 45 3 1 3
41 250.000 490.0 NA 1.0 NA 23.6 440 5 5 5
47 4.288 39.2 NA NA 12.5 13.7 63 2 2 2
53 14.830 98.2 NA NA 2.6 17.0 150 5 5 5
55 1.400 12.5 NA NA 11.0 12.7 90 2 2 2
56 0.060 1.0 8.1 2.2 10.3 3.5 NA 3 1 2
62 4.050 17.0 NA NA NA 13.0 38 3 1 1
> sum (is.na (sleep$Dream)) # indicates that the variable Dream has 12 missing values
[1] 12
> mean (is.na (sleep$Dream)) # Table 19% has a missing value on this variable [1] 0.1935484
> mean (! complete.cases (sleep)) # 32% of the instances in the dataset have one or more missing values
[1] 0.3225806
For missing values, it must be borne in mind that the complete.cases () function identifies only NA and NAN missing values, and Inf and-Inf infinite values are regarded as valid values; missing value functions must be used to identify missing values in data objects, such as mydata==NA, whose logic cannot be implemented.
The above is the editor for you to share how to understand the missing values in R language, if you happen to have similar doubts, you might as well refer to the above analysis. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.