R တွင် ကော်လံတစ်ခုအား အမည်ပြောင်းနည်း (ဥပမာများဖြင့်)
R ရှိ ဒေတာဘောင်တစ်ခုရှိ ကော်လံတစ်ခုတည်းကို အမည်ပြောင်းရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။
နည်းလမ်း 1- Base R ကို အသုံးပြု၍ ကော်လံတစ်ခုတည်းကို အမည်ပြောင်းပါ။
#rename column by name colnames(df)[colnames(df) == ' old_name '] <- ' new_name ' #rename column by position #colnames(df)[ 2 ] <- ' new_name '
နည်းလမ်း 2- dplyr ကို အသုံးပြု၍ ကော်လံတစ်ခုအား အမည်ပြောင်းပါ။
library (dplyr) #rename column by name df <- df %>% rename_at(' old_name ', ~' new_name ') #rename column by position df <- df %>% rename_at( 2 , ~' new_name ')
အောက်ဖော်ပြပါ ဥပမာများသည် R ရှိ ဒေတာဘောင်ဖြင့် လက်တွေ့တွင် နည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-
#create data frame df <- data. frame (team=c('A', 'B', 'C', 'D', 'E'), points=c(99, 90, 86, 88, 95), assists=c(33, 28, 31, 39, 34), rebounds=c(30, 28, 24, 24, 28)) #view data frame df team points assists rebounds 1 A 99 33 30 2 B 90 28 28 3 C 86 31 24 4 D 88 39 24 5 E 95 34 28
ဥပမာ 1- Base R ကိုအသုံးပြုပြီး ကော်လံတစ်ခုတည်းကို အမည်ပြောင်းပါ။
အောက်ပါကုဒ်သည် ကော်လံအမည်များကို အသုံးပြု၍ အမှတ်များ ကော်လံကို Total_points သို့ အမည်ပြောင်းနည်းကို ပြသသည်-
#rename 'points' column to 'total_points' colnames(df)[colnames(df) == ' points '] <- ' total_points ' #view updated data frame df team total_points assists rebounds 1 A 99 33 30 2 B 90 28 28 3 C 86 31 24 4 D 88 39 24 5 E 95 34 28
အောက်ပါကုဒ်သည် ကော်လံအနေအထားကို အသုံးပြု၍ အမှတ်များ ကော်လံအား Total_points သို့ အမည်ပြောင်းနည်းကို ပြသသည်-
#rename column in position 2 to 'total_points' colnames(df)[ 2 ] <- ' total_points ' #view updated data frame df team total_points assists rebounds 1 A 99 33 30 2 B 90 28 28 3 C 86 31 24 4 D 88 39 24 5 E 95 34 28
နည်းလမ်းနှစ်ခုလုံးသည် တူညီသောရလဒ်ထွက်သည်ကို သတိပြုပါ။
ဥပမာ 2- dplyr ကို အသုံးပြု၍ ကော်လံတစ်ခုအား အမည်ပြောင်းပါ။
အောက်ပါ ကုဒ်သည် dplyr တွင် rename_at() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ အမှတ်များ ကော်လံအား Total_points သို့ အမည်ပြောင်းနည်းကို ပြသသည်-
library (dplyr) #rename 'points' column to 'total_points' by name df <- df %>% rename_at(' points ', ~' total_points ') #view updated data frame df team total_points assists rebounds 1 A 99 33 30 2 B 90 28 28 3 C 86 31 24 4 D 88 39 24 5 E 95 34 28
အောက်ပါကုဒ်သည် dplyr တွင် rename_at() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ အမှတ်များ ကော်လံအား total_points သို့ အမည်ပြောင်းနည်းကို ပြသသည်-
library (dplyr) #rename column in position 2 to 'total_points' df <- df %>% rename_at( 2 , ~' total_points ') #view updated data frame df team total_points assists rebounds 1 A 99 33 30 2 B 90 28 28 3 C 86 31 24 4 D 88 39 24 5 E 95 34 28
နည်းလမ်းနှစ်ခုလုံးသည် တူညီသောရလဒ်ထွက်သည်ကို သတိပြုပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
R တွင် သီးခြားကော်လံများကို မည်သို့ရွေးချယ်ရမည်နည်း။
R တွင် အချို့သောကော်လံများကို မည်သို့ထိန်းသိမ်းနည်း
R တွင် ကော်လံများစွာဖြင့် စီရန်