Na များကို r တွင် ကြိုးများဖြင့် အစားထိုးနည်း (ဥပမာများဖြင့်)
R ရှိ ဒေတာဘောင်ကော်လံတစ်ခုရှိ NAs များကို သီးခြားစာကြောင်းများဖြင့် အစားထိုးရန် Tidyr အထုပ်မှ replace_na() လုပ်ဆောင်ချက်ကို သင်အသုံးပြုနိုင်သည်-
#replace NA values in column x with "missing"
df$x %>% replace_na (' none ')
ဒေတာဘောင်၏ ကော်လံအများအပြားရှိ NA များကို သီးခြားစာကြောင်းများဖြင့် အစားထိုးရန် ဤလုပ်ဆောင်ချက်ကို သင်အသုံးပြုနိုင်သည်-
#replace NA values in column x with "missing" and NA values in column y with "none" df %>% replace_na (list(x = ' missing ', y = ' none '))
အောက်ဖော်ပြပါ ဥပမာများသည် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ 1- ကော်လံတစ်ခုရှိ စာကြောင်းများဖြင့် NA များကို အစားထိုးပါ။
အောက်ပါကုဒ်သည် ဒေတာဘောင်တစ်ခု၏ကော်လံတွင် သီးခြားစာကြောင်းတစ်ခုဖြင့် NAs များကို မည်သို့အစားထိုးရမည်ကို ပြသသည်-
library (tidyr)
df <- data. frame (status=c('single', 'married', 'married', NA),
education=c('Assoc', 'Bach', NA, 'Master'),
income=c(34, 88, 92, 90))
#view data frame
df
status education income
1 single Assoc 34
2 married Bach 88
3 married <NA> 92
4 <NA> Master 90
#replace missing values with 'single' in status column
df$status <- df$status %>% replace_na (' single ')
#view updated data frame
df
status education income
1 single Assoc 34
2 married Bach 88
3 married <NA> 92
4 single Master 90
ဥပမာ 2- ကော်လံများစွာရှိ NA များကို စာကြောင်းများဖြင့် အစားထိုးပါ။
အောက်ပါကုဒ်သည် ဒေတာဘောင်တစ်ခု၏ ကော်လံအများအပြားတွင် သီးခြားစာကြောင်းတစ်ခုဖြင့် NAs များကို အစားထိုးနည်းကို ပြသသည်-
library (tidyr)
df <- data. frame (status=c('single', 'married', 'married', NA),
education=c('Assoc', 'Bach', NA, 'Master'),
income=c(34, 88, 92, 90))
#view data frame
df
status education income
1 single Assoc 34
2 married Bach 88
3 married <NA> 92
4 <NA> Master 90
#replace missing values with 'single' in status column
df <- df %>% replace_na (list(status = ' single ', education = ' none '))
#view updated data frame
df
status education income
1 single Assoc 34
2 married Bach 88
3 married none 92
4 single Master 90
ထပ်လောင်းအရင်းအမြစ်များ
R တွင် အချို့သော သို့မဟုတ် အားလုံးကို NA များဖြင့် အတန်းများကို ဖျက်နည်း
NA ကို dplyr တွင် Zero ဖြင့် အစားထိုးနည်း