R တွင် တစ်ခုမှလွဲ၍ ကော်လံအားလုံးကို မည်သို့ရွေးရမည်နည်း။
R ရှိ ဒေတာဘောင်ရှိ ကော်လံတစ်ခုမှလွဲ၍ အားလုံးကို ရွေးချယ်ရန် အောက်ပါနည်းလမ်းများကို အသုံးပြုနိုင်သည်။
နည်းလမ်း 1- ရာထူးတစ်ခုလျှင် တစ်ခုမှလွဲ၍ ကော်လံအားလုံးကို ရွေးပါ။
#select all but the third column
df[, -3]
နည်းလမ်း 2- အမည်တစ်ခုမှလွဲ၍ ကော်လံအားလုံးကို ရွေးပါ။
#select all but column named 'this_column' df[, colnames(df)[colnames(df) != ' this_column ']]
အောက်ဖော်ပြပါ ဥပမာများသည် 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- ရာထူးတစ်ခုလျှင် တစ်ခုမှလွဲ၍ ကော်လံအားလုံးကို ရွေးပါ။
အောက်ပါကုဒ်သည် ဒေတာဘောင်ရှိ တတိယနေရာမှလွဲ၍ ကော်လံအားလုံးကို မည်သို့ရွေးချယ်ရမည်ကို ပြသသည်-
#select all but the third column
df[, -3]
team points rebounds
1 A 99 30
2 B 90 28
3 C 86 24
4 D 88 24
5 E 95 28
ဒေတာဘောင်ရှိ တတိယနေရာမှလွဲ၍ ကော်လံအားလုံးကို ရွေးထားကြောင်း သတိပြုပါ။
ဥပမာ 2- အမည်တစ်ခုမှလွဲ၍ ကော်လံအားလုံးကို ရွေးပါ။
အောက်ပါကုဒ်သည် “ assists” အမည်ရှိ ကော်လံမှလွဲ၍ ဒေတာဘောင်တစ်ခုလုံးကို ရွေးချယ်နည်းကို ပြသသည်-
#select all columns except the column with the name 'assists' df[, colnames(df)[colnames(df) != ' assists ']] team points rebounds 1 A 99 30 2 B 90 28 3 C 86 24 4 D 88 24 5 E 95 28
“အကူအညီ” တံဆိပ်တပ်ထားသည့် တစ်ခုမှလွဲ၍ ကော်လံအားလုံးကို ရွေးထားကြောင်း သတိပြုပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
R ရှိ အခြားကော်လံများကို အခြေခံ၍ ဒေတာဘောင်သို့ ကော်လံထည့်နည်း
R တွင် ကော်လံများစွာဖြင့် စီရန်
R တွင် ကော်လံများကို မည်သို့ပြန်စီရမည်နည်း။