R တွင် ကြိုးများကို နှိုင်းယှဉ်နည်း (ဥပမာ 3 ခု)
R တွင် စာကြောင်းများကို နှိုင်းယှဉ်ရန် အောက်ပါနည်းလမ်းများကို သင်သုံးနိုင်သည်။
နည်းလမ်း 1- ကြိုးနှစ်ချောင်းကို နှိုင်းယှဉ်ပါ။
#case-sensitive comparison string1 == string2 #case-insensitive comparison tolower (string1) == tolower (string2)
နည်းလမ်း 2- string vector နှစ်ခုကို နှိုင်းယှဉ်ပါ။
#case-sensitive comparison identical(vector1, vector2) #case-insensitive comparison identical( tolower (vector1), tolower (vector2))
နည်းလမ်း 3- string vector နှစ်ခုကြား တူညီမှုများကို ရှာပါ။
#find which strings in vector1 are also in vector2
vector1[vector1 %in% vector2]
အောက်ဖော်ပြပါ ဥပမာများသည် နည်းလမ်းတစ်ခုစီကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ 1- vector နှစ်ခု တူညီခြင်းရှိမရှိ စစ်ဆေးပါ။
အောက်ပါကုဒ်သည် R တွင် စာကြောင်းနှစ်ခုကို ညီမျှခြင်းရှိမရှိ ဆုံးဖြတ်ရန် မည်သို့နှိုင်းယှဉ်ရမည်ကို ပြသသည်-
#define two strings string1 <- "Mavericks" string2 <- "mavericks" #case-sensitive comparison string1 == string2 [1] FALSE #case-insensitive comparison tolower (string1) == tolower (string2) [1] TRUE
စာကြောင်းနှစ်ခုသည် အတိအကျတူညီခြင်းမရှိသောကြောင့် စာလုံးအကြီးအသေးအကဲဆတ်သော နှိုင်းယှဉ်မှုသည် FALSE ကို ပြန်ပေးသည်။
သို့သော်လည်း၊ စာလုံးအသေးမရှိသော နှိုင်းယှဉ်ချက်သည် စာလုံးနှစ်လုံးစလုံးတွင် တူညီသည့်အစီအစဥ်တွင် တူညီသောအက္ခရာများပါသောကြောင့် ဖြစ်ရပ်မှန်ကို ပြန်ပေးပါသည်။
ဥပမာ 2- string vector နှစ်ခုကို နှိုင်းယှဉ်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် string vector နှစ်ခု တူညီခြင်းရှိမရှိ ဆုံးဖြတ်ရန် identical() လုပ်ဆောင်ချက်ကို အသုံးပြုနည်းကို ပြသသည်-
#define two vectors of strings
vector1 <- c("hey", "hello", "HI")
vector2 <- c("hey", "hello", "hi")
#case-sensitive comparison
identical(vector1, vector2)
[1] FALSE
#case-insensitive comparison
identical( tolower (vector1), tolower (vector2))
[1] TRUE
vector နှစ်ခုတွင် တူညီသောစာကြောင်းများ အတိအကျမပါဝင်သောကြောင့် case-sensitive နှိုင်းယှဉ်မှုသည် FALSE တန်ဖိုးကို ပြန်ပေးပါသည်။
သို့သော်လည်း၊ case-insensitive နှိုင်းယှဥ်မှုသည် မှန်ကန် သည်ဖြစ်စေ ၊ vector နှစ်ခုလုံးတွင် တူညီသောစာကြောင်းများပါဝင်သည် ၊ မည်သည်ပင်ဖြစ်ပါစေ၊
ဥပမာ 3- string vector နှစ်ခုကြား တူညီမှုများကို ရှာဖွေခြင်း။
အောက်ဖော်ပြပါ ကုဒ်သည် အခြား vector တစ်ခုနှင့် သက်ဆိုင်သည့် မည်သည့် string များကို ရှာဖွေရန် %in% အော်ပရေတာအား အသုံးပြုနည်းကို ပြသသည်-
#define two vectors of strings
vector1 <- c("hey", "hello", "greetings")
vector2 <- c("hey", "hello", "hi")
#find which strings in vector1 are also in vector2
vector1[vector1 %in% vector2]
[1] “hey” “hello”
ရလဒ်မှ၊ “ ဟေး” နှင့် “ ဟယ်လို” စာကြောင်းများသည် vector1 နှင့် vector2 နှစ်ခုစလုံးတွင်ရှိသည်ကိုကျွန်ုပ်တို့တွေ့မြင်နိုင်သည်။
ဆက်စပ်မှု- R တွင် %in% အော်ပရေတာအား အသုံးပြုနည်း
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားသော ဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
R တွင် ကော်လံနှစ်ခုကို နှိုင်းယှဉ်နည်း
R တွင် vector နှစ်ခုကို နှိုင်းယှဉ်နည်း
R တွင် string တစ်ခုရှိ ဇာတ်ကောင်တည်နေရာကို မည်သို့ရှာရမည်နည်း။
Vector ကို R ဖြင့် string သို့ပြောင်းနည်း