R တွင် စာရင်းခွဲနည်း (ဥပမာများဖြင့်)


R တွင် စာရင်းခွဲများပြုလုပ်ရန် အောက်ပါ syntax ကို သင်အသုံးပြုနိုင်သည်-

 #extract first list item
my_list[[1]]

#extract first and third list item
my_list[c(1, 3)]

#extract third element from the first item
my_list[[c(1, 3)]] 

အောက်ပါနမူနာများသည် အောက်ပါစာရင်းဖြင့် ဤ syntax ကိုမည်သို့အသုံးပြုရမည်ကိုပြသသည်-

 #create list
my_list <- list(a = 1:3, b = 7, c = " hey ")

#view list
my_list

$a
[1] 1 2 3

$b
[1] 7

$c
[1] “hey”

ဥပမာ 1- စာရင်းအကြောင်းအရာတစ်ခုကို ထုတ်ယူပါ။

အောက်ပါကုဒ်သည် စာရင်းအကြောင်းအရာတစ်ခုကို ထုတ်ယူရန် နည်းလမ်းအမျိုးမျိုးကို ပြသည်-

 #extract first list item using index value
my_list[[1]]

[1] 1 2 3

#extract first list item using name
my_list[[" a "]]

[1] 1 2 3

#extract first list item using name with $ operator
my_list$a

[1] 1 2 3

နည်းလမ်းသုံးခုစလုံးသည် တူညီသောရလဒ်ကို ဖြစ်ပေါ်စေကြောင်း သတိပြုပါ။

ဥပမာ 2- စာရင်းများစွာကို ထုတ်ယူပါ။

အောက်ပါကုဒ်သည် စာရင်းအရာများစွာကို ထုတ်ယူရန် မတူညီသောနည်းလမ်းများကို ပြသသည်-

 #extract first and third list item using index values
my_list[c(1, 3)]

$a
[1] 1 2 3

$c
[1] “hey”

#extract first and third list item using names
my_list[c(" a ", " c ")]

$a [1] 1 2 3

$c [1] "hey"

နည်းလမ်းနှစ်ခုစလုံးသည် တူညီသောရလဒ်ကို ဖြစ်ပေါ်စေသည်။

ဥပမာ 3- စာရင်းအကြောင်းအရာတစ်ခုမှ သီးခြားအကြောင်းအရာတစ်ခုကို ထုတ်ယူပါ။

အောက်ဖော်ပြပါ ကုဒ်သည် စာရင်းအကြောင်းအရာတစ်ခုမှ သီးခြားအရာတစ်ခုကို ထုတ်ယူရန် နည်းလမ်းအမျိုးမျိုးကို ပြသည်-

 #extract third element from the first item using index values
my_list[[c(1, 3)]] 

[1] 3

#extract third element from the first item using double brackets
my_list[[1]][[3]]

[1] 3

နည်းလမ်းနှစ်ခုစလုံးသည် တူညီသောရလဒ်ကို ဖြစ်ပေါ်စေသည်။

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

စာရင်းတစ်ခုအား R တွင်ဒေတာဘောင်တစ်ခုသို့မည်ကဲ့သို့ပြောင်းရမည်နည်း။
R တွင် စာရင်းထဲသို့ တန်ဖိုးများထည့်နည်း

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

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