Dplyr ကို အသုံးပြု၍ ကော်လံများစွာကို အကျဉ်းချုပ်နည်း
dplyr ကို အသုံးပြု၍ ဒေတာဘောင်တစ်ခုရှိ ကော်လံအများအပြားကို အကျဉ်းချုပ်ရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်သည်-
နည်းလမ်း 1- ကော်လံအားလုံးကို အကျဉ်းချုပ်ပါ။
#summarize mean of all columns df %>% group_by(group_var) %>% summarise(across(everything(), mean, na. rm = TRUE ))
နည်းလမ်း 2- တိကျသောကော်လံများကို အကျဉ်းချုံ့ပါ။
#summarize mean of col1 and col2 only df %>% group_by(group_var) %>% summarise(across(c(col1, col2), mean, na. rm = TRUE ))
နည်းလမ်း 3- ကိန်းဂဏာန်းကော်လံများအားလုံးကို အကျဉ်းချုပ်ပါ။
#summarize mean and standard deviation of all numeric columns df %>% group_by(group_var) %>% summarise(across(where(is. numeric ), list(mean=mean, sd=sd), na. rm = TRUE ))
အောက်ပါဥပမာများသည် အောက်ပါဒေတာဘောင်ဖြင့် နည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-
#create data frame df <- data. frame (team=c('A', 'A', 'A', 'B', 'B', 'B'), points=c(99, 90, 86, 88, 95, 90), assists=c(33, 28, 31, 39, 34, 25), rebounds=c(NA, 28, 24, 24, 28, 19)) #view data frame df team points assists rebounds 1 A 99 33 NA 2 A 90 28 28 3 A 86 31 24 4 B 88 39 24 5 B 95 34 28 6 B 90 25 19
ဥပမာ 1- ကော်လံအားလုံးကို အကျဉ်းချုပ်ပါ။
အောက်ပါကုဒ်သည် ကော်လံအားလုံး၏ ပျမ်းမျှအား အကျဉ်းချုံးနည်းကို ပြသသည်-
library (dplyr) #summarize mean of all columns, grouped by team df %>% group_by(team) %>% summarise(across(everything(), mean, na. rm = TRUE )) # A tibble: 2 x 4 team points assists rebounds 1 A 91.7 30.7 26 2 B 91 32.7 23.7
ဥပမာ 2- သီးခြားကော်လံများကို အကျဉ်းချုပ်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် အမှတ် မျှသာ၏ ပျမ်းမျှအား အကျဉ်းချုပ်နည်းနှင့် ကော်လံများကို ပြန်လှန် နည်းကို ပြသည်-
library (dplyr) #summarize mean of points and rebounds, grouped by team df %>% group_by(team) %>% summarise(across(c(points, rebounds), mean, na. rm = TRUE )) # A tibble: 2 x 3 team points rebounds 1 A 91.7 26 2 B 91 23.7
ဥပမာ 3- ဂဏန်းကော်လံများအားလုံးကို အကျဉ်းချုပ်ပါ။
အောက်ပါကုဒ်သည် ဒေတာဘောင်ရှိ ကိန်းဂဏာန်းကော်လံအားလုံး၏ ပျမ်းမျှနှင့် စံသွေဖည်မှုကို အကျဉ်းချုံ့နည်းကို ပြသည်-
library (dplyr) #summarize mean and standard deviation of all numeric columns df %>% group_by(team) %>% summarise(across(where(is. numeric ), list(mean=mean, sd=sd), na. rm = TRUE )) # A tibble: 2 x 7 team points_mean points_sd assists_mean assists_sd rebounds_mean rebounds_sd 1 A 91.7 6.66 30.7 2.52 26 2.83 2 B 91 3.61 32.7 7.09 23.7 4.51
အထွက်သည် ဒေတာဘောင်ရှိ ကိန်းဂဏာန်းကိန်းရှင်များအားလုံး၏ ပျမ်းမျှနှင့် စံသွေဖည်မှုကို ပြသသည်။
ဤဥပမာတွင် ကျွန်ုပ်တို့တွက်ချက်လိုသော အနှစ်ချုပ်ကိန်းဂဏန်းများစွာကို စာရင်းပြုစုရန် list() လုပ်ဆောင်ချက်ကို အသုံးပြုခဲ့သည်ကို သတိပြုပါ။
မှတ်ချက် – ဥပမာတစ်ခုစီတွင်၊ ကျွန်ုပ်တို့သည် dplyr cross() လုပ်ဆောင်ချက်ကို အသုံးပြုခဲ့သည်။ ဤလုပ်ဆောင်ချက်အတွက် စာရွက်စာတမ်းအပြည့်အစုံကို ဤနေရာတွင် ရှာဖွေနိုင်ပါသည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် dplyr ကို အသုံးပြု၍ အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
dplyr ကို အသုံးပြု၍ အတန်းများကို ဖျက်နည်း
dplyr ကို အသုံးပြု၍ အတန်းများကို မည်သို့စီစဉ်မည်နည်း။
dplyr ကို အသုံးပြု၍ အခြေအနေများစွာဖြင့် စစ်ထုတ်နည်း