R语言 使用较大的引用列表对多列排序

eqqqjvef  于 2023-06-19  发布在  其他
关注(0)|答案(1)|浏览(106)

这是我的样本df有486列

Source          Target Value    Category_links
ANACANTHOBATIDAELC  9   Least Concerned 
ARHYNCHOBATIDAE DD  1   Data Deficient
ARHYNCHOBATIDAE LC  36  Least Concerned 
ARHYNCHOBATIDAE NT  9   Near Threatened 
ARHYNCHOBATIDAE VU  3   Vulnerable  
ARHYNCHOBATIDAE EN  3   Endangered
ARHYNCHOBATIDAE CR  2   Critically Endangered   
CARCHARHINIDAE  NT  2   Near Threatened 
CARCHARHINIDAE  VU  7   Vulnerable

这是我的样本参考列表57列

-----------------------
       Family
-----------------------
1  |    Heterodontidae|
2  ||Chlamydoselachidae|
3  |       Hexanchidae|
4  |    Rhincodontidae|
5  |     Orectolobidae|
6  |    Odontaspididae|
7  |          Lamnidae|
8  |         Alopiidae|
9  |    Hemiscylliidae|
10 |    Brachaeluridae|
11 |   Stegostomatidae|
12 |Ginglymostomatidae|
13 |     Megachasmidae|
14 |    Scyliorhinidae|
15 |    Carcharhinidae|
16 |        Sphyrnidae|
17 |         Triakidae|
18 |     Proscylliidae|
19 |    Hemigaleidae|
20 |        Squalidae|
21 |   Pristiophoridae|

我想对df中的'Source'列按照引用列表中'Family'的顺序进行排序,避免引用列表中给出任何额外的'Family'

dfty9e19

dfty9e191#

library(dplyr)

sample_df |> 
  arrange(ordered(source, levels = reference_list))

相关问题