R တွင် စာကြောင်းများ ပေါင်းစပ်နည်း (ဥပမာများဖြင့်)
စာကြောင်းများစွာကို အမြန်ပေါင်းစပ်ရန် R တွင် paste() လုပ်ဆောင်ချက်ကို သင်အသုံးပြုနိုင်သည်-
paste(string1, string2, string3, sep = " ")
အောက်ဖော်ပြပါ ဥပမာများသည် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ 1- string vector များကို ပေါင်းစပ်ခြင်း။
R တွင် အောက်ပါစာကြောင်းများရှိသည်ဆိုပါစို့။
#create three string variables
a <- “hey”
b <- “there”
c <- “friend”
ဤစာကြောင်းသုံးခုကို စာကြောင်းတစ်ခုတည်းသို့ အမြန်ပေါင်းစပ်ရန် paste() လုပ်ဆောင်ချက်ကို ကျွန်ုပ်တို့အသုံးပြုနိုင်သည်-
#concatenate the three strings into one string
d <- paste(a, b, c)
#view result
d
[1] “hey there friend”
ကြိုးသုံးချောင်းကို ကွက်လပ်များဖြင့် ပိုင်းခြားထားသော ကြိုးတန်းတစ်ခုတည်းအဖြစ် ပေါင်းစပ်ထားသည်။
Sep argument တွင် မတူညီသောတန်ဖိုးတစ်ခုကို ပေးခြင်းဖြင့် ခြားနားသောတန်ဖိုးတစ်ခုကိုလည်း အသုံးပြုနိုင်ပါသည်။
#concatenate the three strings into one string, separated by dashes
d <- paste(a, b, c, sep = "-")
[1] “hey-there-friend”
ဥပမာ 2- ဒေတာဘောင်တစ်ခုတွင် စာကြောင်းများ၏ကော်လံများကို ပေါင်းစပ်ပါ။
R တွင် အောက်ပါ data frame ရှိသည်ဆိုပါစို့။
#create data frame
df <- data. frame (first=c('Andy', 'Bob', 'Carl', 'Doug'),
last=c('Smith', 'Miller', 'Johnson', 'Rogers'),
dots=c(99, 90, 86, 88))
#view data frame
df
first last points
1 Andy Smith 99
2 Bob Miller 90
3 Carl Johnson 86
4 Doug Rogers 88
“ ပထမ” နှင့် “ နောက်ဆုံး” ကော်လံများကို “ အမည်” ဟုခေါ်သော ကော်လံအသစ်တစ်ခုသို့ ပေါင်းစပ်ရန် Paste() လုပ်ဆောင်ချက်ကို ကျွန်ုပ်တို့ အသုံးပြုနိုင်ပါသည်။
#concatenate 'first' and 'last' name columns into one column
df$name = paste(df$first, df$last)
#view updated data frame
df
first last points name
1 Andy Smith 99 Andy Smith
2 Bob Miller 90 Bob Miller
3 Carl Johnson 86 Carl Johnson
4 Doug Rogers 88 Doug Rogers
“ ပထမ” နှင့် “ နောက်ဆုံး” ကော်လံများရှိ စာကြောင်းများကို “ အမည်” ကော်လံတွင် ပေါင်းစပ်ထားကြောင်း သတိပြုပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားသော ဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
R တွင် vector မှ string ကိုမည်သို့ပြောင်းရမည်နည်း။
R တွင် စာလုံးအသေးသို့ strings များကို မည်သို့ပြောင်းရမည်နည်း။
R တွင် တစ်စိတ်တစ်ပိုင်းစာကြောင်း ကိုက်ညီအောင် မည်သို့လုပ်ဆောင်ရမည်နည်း။