R Language Learning Note (16): Handling Missing values

Source: Internet
Author: User

#识别缺失值install. Packages ("Vim") data (sleep,package= "vim") #列出没有缺失值的行sleep [Complete.cases (Sleep),]# Lists rows sleep[!complete.cases (sleep) with one or more missing values,] #有多少个缺失值sum (Is.na (sleep$dream)) #sleep The data for a percentage of the $dream is mean with missing values ( Is.na (Sleep$dream)) #数据集中多个行包含缺失值mean (!complete.cases (Sleep)) #探索缺失值install. Packages ("mice") the library (MICE) data ( Sleep,package= "Vim") Md.pattern (Sleep) #图形探索library ("Vim") Aggr (Sleep,prop=false,numbers=true)
Matrixplot (Sleep)
Marginplot (Sleep[c ("Gest", "Dream")],pch=c ("Col=c", "Red", "blue")
#用相关性探索缺失值x <-as.data.frame (is.na (Sleep)) head (sleep,n=5) head (x,n=5) Y<-x[which (Apply (X,2,sum) >0)] Cor (y)

Nond Dream Sleep Span Gest
Nond 1.00 0.91 0.49 0.02-0.14
Dream 0.91 1.00 0.20 0.04-0.13
Sleep 0.49 0.20 1.00-0.07-0.07
Span 0.02 0.04-0.07 1.00 0.20
gest-0.14-0.13-0.07 0.20 1.00

Cor (sleep,y,use= "Pairwise.complete.obs")

Nond Dream Sleep Span Gest
BODYWGT 0.23 0.22 0.002-0.06-0.05
BRAINWGT 0.18 0.16 0.008-0.08-0.07
Nond na na na-0.04-0.05
Dream-0.19 NA-0.189 0.12 0.23
sleep-0.08-0.08 NA 0.10 0.04
Span 0.08 0.06 0.005 NA-0.07
Gest 0.20 0.05 0.160-0.17 NA
Pred 0.05-0.07 0.202 0.02-0.20
EXP 0.25 0.13 0.261-0.19-0.19
Danger 0.07-0.07 0.209-0.07-0.20

#行删除newdata <-mydata[complete.cases (MyData),]newdata<-na.omit (MyData) options (Digits=1) Cor (na.omit (sleep)) FIT<-LM (Dream~span+gest,data=na.omit (Sleep)) Summary (FIT) #多重插补library (MICE) data (sleep,package= "VIM") imp<- Mice (sleep,seed=1234) Fit<-with (IMP,LM (dream~span+gest)) Pooled<-pool (FIT) Summary (Pooled) impimp$imp$ Dreamdataset3<-complete (imp,action=3) dataset3  #多重删补后的结果

BODYWGT brainwgt nond Dream Sleep Span Gest Pred Exp Danger
1 7e+03 6e+03 2 0.5 3 39 645 3 5 3
2 1e+00 7e+00 6 2.0 8 4 42 3 1 3
3 3e+00 4e+01 11 1.5 12 14 60 1 1 1
4 9e-01 6e+00 13 3.4 16 2 25 5 2 3
5 3e+03 5e+03 2 1.8 4 69 624 3 5 4
6 1e+01 2e+02 9 0.7 10 27 180 4 4 4
7 2e-02 3e-01 16 3.9 20 19 35 1 1 1
8 2e+02 2e+02 5 1.0 6 30 392 4 5 4
9 3e+00 3e+01 11 3.6 14 28 63 1 2 1
5E+01 4e+02 8 1.4 10 50 230 1 1 1
4E-01 6e+00 11 1.5 12 7 112 5 4 4
5E+02 4e+02 3 0.7 4 30 281 5 5 5
6E-01 2e+00 8 2.7 10 18 46 2 1 2
2E+02 4e+02 3 0.5 3 40 365 5 5 5
7E-02 1e+00 6 2.1 8 4 42 1 1 1
3e+00 2e+01 9 0.0 9 50 28 2 2 2
8e-01 4e+00 7 4.1 11 6 42 2 2 2
2E-01 5e+00 10 1.2 11 10 120 2 2 2
1E+00 2e+01 5 1.3 6 34 28 1 2 1
6E+01 8e+01 12 6.1 18 7 21 1 1 1
5E+02 7e+02 11 0.3 11 28 400 5 5 5
3E+01 1e+02 3 0.5 4 20 148 5 5 5
1E-01 1e+00 11 3.4 14 4 16 3 1 2
2E+02 4e+02 8 3.6 12 39 252 1 4 1
8E+01 3e+02 5 1.5 6 41 310 1 3 1
4E+01 1e+02 11 2.0 13 16 63 1 1 1
1E-01 4e+00 10 3.4 14 9 28 5 1 3
1e+00 6e+00 7 0.8 8 8 68 5 3 4
5E+02 7e+02 2 0.8 3 46 336 5 5 5
1E+02 2e+02 7 3.4 11 22 100 1 1 1
4E+01 6e+01 3 0.6 4 16 33 3 5 4
5E-03 1e-01 8 1.4 9 3 22 5 2 4
1E-02 2e-01 18 2.0 20 24 50 1 1 1
6E+01 1e+03 6 1.9 8 100 267 1 1 1
1E-01 3e+00 8 2.4 11 13 30 2 1 1
1e+00 8e+00 8 2.8 11 4 45 3 1 3
PNS 2e-02 4e-01 12 1.3 13 3 19 4 1 3
5E-02 3e-01 11 2.0 13 2 30 4 1 3
2e+00 6e+00 14 5.6 19 5 12 2 1 1
4e+00 1e+01 14 3.1 17 6 120 2 1 1
2E+02 5E+02 8 1.0 8 24 440 5 5 5
5E-01 2e+01 15 1.8 17 12 140 2 2 2
1E+01 1e+02 10 0.9 11 20 170 4 4 4
2e+00 1e+01 12 1.8 14 13 17 2 1 2
2E+02 2e+02 6 1.9 8 27 115 4 4 4
2e+00 1e+01 8 0.9 8 18 31 5 5 5
4e+00 4e+01 11 1.5 12 14 63 2 2 2
3E-01 2e+00 11 2.6 13 5 21 3 1 3
4e+00 5e+01 7 2.4 10 10 52 1 1 1
7E+00 2e+02 8 1.2 10 29 164 2 3 2
Wuyi 8e-01 1e+01 6 0.9 7 7 225 2 2 2
4e+00 2e+01 5 0.5 5 6 225 3 2 3
1E+01 1e+02 2 0.5 3 17 150 5 5 5
6E+01 2e+02 3 0.6 4 20 151 5 5 5
1e+00 1e+01 8 2.6 11 13 90 2 2 2
6E-02 1e+00 8 2.2 10 4 100 3 1 2
9E-01 3e+00 11 2.3 13 4 60 2 1 2
2e+00 1e+01 5 0.5 5 8 200 3 1 3
1E-01 2e+00 13 2.6 16 2 46 3 2 2
4e+00 6e+01 10 0.6 10 24 210 4 3 4
4e+00 4e+00 13 6.6 19 3 14 2 1 1
4e+00 2e+01 18 0.5 19 13 38 3 1 1

#成对删除cor (sleep,use= "Pairwise.complete.obs")

R Language Learning Note (16): Handling Missing values

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.