A- ကော်လံများစွာသည် တူညီမှုရှိမရှိ စစ်ဆေးနည်း


R ရှိ ဒေတာဘောင်တစ်ခုတွင် ကော်လံများစွာသည် တူညီမှုရှိမရှိ စစ်ဆေးရန် အောက်ပါနည်းလမ်းများကို အသုံးပြုနိုင်သည်။

နည်းလမ်း 1- ကော်လံများအားလုံး တူညီမှုရှိမရှိ စစ်ဆေးပါ။

 library (dplyr)

#create new column that checks if all columns are equal
df <- df %>%
        rowwise %>%
        mutate(match = n_distinct(unlist(cur_data())) == 1 ) %>%
        A group()

နည်းလမ်း 2- သတ်မှတ်ထားသောကော်လံများ တူညီမှုရှိမရှိ စစ်ဆေးပါ။

 library (dplyr)

#create new column that checks if columns 'A', 'C', and 'D' are equal
df_temp <- df %>%
             select(' A ', ' C ', ' D ') %>%
             rowwise %>%
             mutate(match = n_distinct(unlist(cur_data())) == 1 ) %>%
             A group()

#add new column to existing data frame
df$match <- df_temp$match

အောက်ပါဥပမာများသည် အောက်ပါဒေတာဘောင်ဖြင့် နည်းလမ်းတစ်ခုစီကို လက်တွေ့အသုံးပြုနည်းကို ပြသသည်-

 #create data frame
df = data. frame (A=c(4, 0, 3, 3, 6, 8, 7),
                B=c(4, 2, 3, 5, 6, 4, 7),
                C=c(4, 0, 3, 3, 5, 10, 7),
                D=c(4, 0, 3, 3, 3, 8, 7))

#view data frame
df

  ABCD
1 4 4 4 4
2 0 2 0 0
3 3 3 3 3
4 3 5 3 3
5 6 6 5 3
6 8 4 10 8
7 7 7 7 7

ဥပမာ 1- ကော်လံအားလုံး တူညီမှုရှိမရှိ စစ်ဆေးပါ။

ဒေတာဘောင်ရှိ ကော်လံတစ်ခုစီ၏ တန်ဖိုးသည် အတန်းတစ်ခုစီအတွက် ညီမျှခြင်းရှိမရှိ စစ်ဆေးရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။

 library (dplyr)

#create new column that checks if all columns are equal
df <- df %>%
        rowwise %>%
        mutate(match = n_distinct(unlist(cur_data())) == 1 ) %>%
        A group()

#view updated data frame
df

# A tibble: 7 x 5
      ABCD match
      
1 4 4 4 4 TRUE 
2 0 2 0 0 FALSE
3 3 3 3 3 TRUE 
4 3 5 3 3 FALSE
5 6 6 5 3 FALSE
6 8 4 10 8 FALSE
7 7 7 7 7 TRUE 

ကော်လံတစ်ခုစီ၏တန်ဖိုးသည် တူညီပါက၊ ကိုက်ညီသော ကော်လံသည် True ပြန်ပေးသည်။

မဟုတ်ပါက False ပြန်တက်လာသည်။

အောက်ပါအတိုင်း as.numeric() ကို အသုံးပြု၍ True နှင့် False တန်ဖိုးများကို 1 နှင့် 0 သို့ ပြောင်းနိုင်သည်ကို သတိပြုပါ။

 library (dplyr)

#create new column that checks if all columns are equal
df <- df %>%
        rowwise %>%
        mutate(match = as. numeric (n_distinct(unlist(cur_data())) == 1 )) %>%
        A group()

#view updated data frame
df

# A tibble: 7 x 5
      ABCD match
      
1 4 4 4 4 1
2 0 2 0 0 0
3 3 3 3 3 1
4 3 5 3 3 0
5 6 6 5 3 0
6 8 4 10 8 0
7 7 7 7 7 1

ဥပမာ 2- သတ်မှတ်ထားသောကော်လံများ တူညီမှုရှိမရှိ စစ်ဆေးပါ။

ဒေတာဘောင်၏ ကော်လံ A၊ C နှင့် D ရှိ တန်ဖိုးများသည် အတန်းတစ်ခုစီအတွက် ညီမျှခြင်းရှိမရှိ စစ်ဆေးရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်သည်။

 library (dplyr)

#create new column that checks if columns 'A', 'C', and 'D' are equal
df_temp <- df %>%
             select(' A ', ' C ', ' D ') %>%
             rowwise %>%
             mutate(match = n_distinct(unlist(cur_data())) == 1 ) %>%
             A group()

#add new column to existing data frame
df$match <- df_temp$match

#view updated data frame
df

  ABCD match
1 4 4 4 4 TRUE
2 0 2 0 0 TRUE
3 3 3 3 3 TRUE
4 3 5 3 3 TRUE
5 6 6 5 3 FALSE
6 8 4 10 8 FALSE
7 7 7 7 7 TRUE

ကော်လံ A၊ C၊ နှင့် D တို့တွင် တန်ဖိုးများ တူညီပါက၊ ကိုက်ညီသော ကော်လံသည် True ဖြစ်သည်

မဟုတ်ပါက False ပြန်တက်လာသည်။

ထပ်လောင်းအရင်းအမြစ်များ

အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-

R တွင် ကော်လံများစွာဖြင့် စီရန်
R တွင် အချို့သောကော်လံများကို မည်သို့ထိန်းသိမ်းနည်း
R ရှိ ကော်လံများတွင် ဖြစ်ပွားမှုအရေအတွက်ကို ရေတွက်နည်း

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

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