R တွင် အချို့သော သို့မဟုတ် အားလုံးကို na များဖြင့် အတန်းများကို ဖျက်နည်း


R ရှိ ဒေတာဘောင်တစ်ခုတွင် NA များ (ပျောက်နေသောတန်ဖိုးများ) ပါဝင်သော အတန်းများကို မကြာခဏ ဖယ်ရှားလိုပေမည်။

Basic R နှင့် Tidyr ပက်ကေ့ဂျ်ကို အသုံးပြု၍ ဤစာကြောင်းများကို ဖယ်ရှားနည်းကို ဤသင်ခန်းစာတွင် ရှင်းပြထားသည်။ အောက်ဖော်ပြပါ ဥပမာတစ်ခုစီအတွက် အောက်ပါဒေတာဘောင်ကို ကျွန်ုပ်တို့ အသုံးပြုပါမည်-

 #create data frame with some missing values
df <- data.frame(points = c(12, NA, 19, 22, 32),
                 assists = c(4, NA, 3, NA, 5),
                 rebounds = c(5, NA, 7, 12, NA))

#view data frame
df

  points assists rebounds
1 12 4 5
2 NA NA NA
3 19 3 7
4 22 NA 12
5 32 5 NA

Base R ကို အသုံးပြု၍ NA များကို ဖယ်ရှားပါ။

အောက်ပါကုဒ်သည် ကော်လံ တစ်ခု ရှိ လွဲမှားနေသောတန်ဖိုးရှိသော ဒေတာဘောင်ရှိ အတန်းအားလုံးကို ဖယ်ရှားရန် complete.cases() ကို အသုံးပြုနည်းကို ပြသသည်-

 #remove all rows with a missing value in any column
df[ complete.cases (df),]

  points assists rebounds
1 12 4 5
3 19 3 7

ဖော်ပြပါကုဒ်သည် တိကျသော ကော်လံများတွင် လွဲမှားနေသောတန်ဖိုးရှိသော ဒေတာဘောင်ရှိ အတန်းများအားလုံးအား ဖယ်ရှားရန် complete.cases() ကို အသုံးပြုနည်းကို ပြသသည်-

 #remove all rows with a missing value in the third column
df[ complete.cases (df[,3]),]

  points assists rebounds
1 12 4 5
3 19 3 7
4 22 NA 12

#remove all rows with a missing value in either the first or third column
df[ complete.cases (df[ , c(1,3)]),]

  points assists rebounds
1 12 4 5
3 19 3 7
4 22 NA 12

Tidyr ကိုအသုံးပြု၍ NA များကိုဖျက်ပါ။

အောက်ပါကုဒ်သည် ကော်လံ တစ်ခု ရှိ လွဲမှားနေသောတန်ဖိုးရှိသော ဒေတာဘောင်တစ်ခုတွင် အတန်းအားလုံးကို ချရန်အတွက် Tidyr ပက်ကေ့ဂျ်မှ drop_na() ကို အသုံးပြုပုံကို ပြသသည်-

 #load tidyr package
library(tidyr)

#remove all rows with a missing value in any column
df %>% drop_na()

  points assists rebounds
1 12 4 5
3 19 3 7

အောက်ပါကုဒ်သည် သတ်မှတ်ထားသော ကော်လံများတွင် လွဲမှားနေသောတန်ဖိုးရှိသော ဒေတာဘောင်တစ်ခုတွင် အတန်းအားလုံးကို ချရန်အတွက် Tidyr ပက်ကေ့ဂျ်မှ drop_na() ကို မည်သို့အသုံးပြုရမည်ကို ပြသသည်-

 #load tidyr package
library(tidyr)

#remove all rows with a missing value in the third column
df %>% drop_na(rebounds)

  points assists rebounds
1 12 4 5
3 19 3 7
4 22 NA 12

နောက်ထပ် R သင်ခန်းစာများကို ဤနေရာတွင် ရှာဖွေနိုင်ပါသည်။

မှတ်ချက်တစ်ခုထည့်ပါ။

သင့် email လိပ်စာကို ဖော်ပြမည် မဟုတ်ပါ။ လိုအပ်သော ကွက်လပ်များကို * ဖြင့်မှတ်သားထားသည်