R တွင် str_trim ကိုအသုံးပြုနည်း (ဥပမာများနှင့်အတူ)


R ရှိ stringr package ၏ str_trim() လုပ်ဆောင်ချက်ကို string တစ်ခုမှ whitespace ဖယ်ရှားရန် အသုံးပြုနိုင်သည်။

ဤလုပ်ဆောင်ချက်သည် အောက်ပါ syntax ကိုအသုံးပြုသည်-

str_trim(string၊ side = c(“နှစ်ခုလုံး”၊ “ဘယ်”၊ “ညာ”))

ရွှေ-

  • string- စာလုံး vector
  • ပုံစံ- နေရာလွတ်များကို ဖယ်ရှားရန် ဘေးဘက်

အောက်ဖော်ပြပါ ဥပမာများသည် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။

ဥပမာ 1- ဘယ်ဘက်ခြမ်းရှိ နေရာလွတ်များကို ဖြတ်ပါ။

အောက်ဖော်ပြပါ ကုဒ်သည် စာကြောင်းတစ်ခု၏ ဘယ်ဘက်ခြမ်းမှ နေရာလွတ်များကို ဖယ်ရှားရန် str_trim() လုပ်ဆောင်ချက်ကို အသုံးပြုပုံကို ပြသသည်-

 library (stringr)

#create string
my_string <- “Hey there everyone.”

#view string
my_string

[1] “Hey there everyone.”

#create new string with white space removed from left
new_string <- str_trim(my_string, side=" left ")

#view new string
new_string

[1] “Hey there everyone.”

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

ဥပမာ 2- ညာဘက်ခြမ်းရှိ နေရာလွတ်များကို ချုံ့ပါ။

အောက်ပါကုဒ်သည် စာကြောင်းတစ်ခု၏ ညာဘက်ခြမ်းမှ နေရာလွတ်များကို ဖယ်ရှားရန် str_trim() လုပ်ဆောင်ချက်ကို အသုံးပြုပုံကို ပြသသည်-

 library (stringr)

#create string
my_string <- “Hey there everyone.”

#view string
my_string

[1] “Hey there everyone.”

#create new string with white space removed from right
new_string <- str_trim(my_string, side=" right ")

#view new string
new_string

[1] “Hey there everyone.”

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

ဥပမာ 3- ဘေးနှစ်ဖက်ရှိ နေရာလွတ်များကို ဖြတ်တောက်ခြင်း။

အောက်ပါကုဒ်သည် str_trim() လုပ်ဆောင်ချက်ကို အသုံးပြုနည်းကို string တစ်ခု၏ နှစ်ဖက်စလုံးမှ နေရာလွတ်များကို ဖယ်ရှားရန် ဖော်ပြသည်-

 library (stringr)

#create string
my_string <- “Hey there everyone.”

#view string
my_string

[1] “Hey there everyone.”

#create new string with white space removed from both sides
new_string <- str_trim(my_string, side=" both ")

#view new string
new_string

[1] “Hey there everyone.”

စာကြောင်းနှစ်ဘက်စလုံးရှိ နေရာလွတ်အားလုံးကို ဖြတ်တောက်ထားကြောင်း သတိပြုပါ။

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

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

R တွင် str_replace ကိုအသုံးပြုနည်း
R တွင် str_split ကိုအသုံးပြုနည်း
R တွင် str_detect ကိုအသုံးပြုနည်း
R တွင် str_count ကိုအသုံးပြုနည်း

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

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