首页 > 解决方案 > 在 R Markdown 中对文章标题进行排序

问题描述

我在 R markdown 中有 50 多个手稿标题,它们是直接从 word 文档中复制而来的。我想知道是否有一个函数或包我可以按字母顺序对这些标题进行排序,这样我就可以在 R markdown 中列出它们。

Hospital admission and mortality rates for non-covid diseases in Denmark during covid-19 pandemic: nationwide population based cohort study

Covid-19 deaths in Africa: prospective systematic postmortem surveillance study

Food anaphylaxis in the United Kingdom: analysis of national data, 1998-2018

Association of first trimester prescription opioid use with congenital malformations in the offspring: population based cohort study

标签: rr-markdown

解决方案


在以下示例中,您应该能够将文本复制到 的text参数中read.tablesep定义条目由换行符分隔,并跳过空行 ( blank.lines.skip = T)

df <- read.table(sep = "\n", blank.lines.skip = T, stringsAsFactors=FALSE, 
  text = "Hospital admission and mortality rates for non-covid diseases in Denmark during covid-19 pandemic: nationwide population based cohort study

Covid-19 deaths in Africa: prospective systematic postmortem surveillance study

Food anaphylaxis in the United Kingdom: analysis of national data, 1998-2018

Association of first trimester prescription opioid use with congenital malformations in the offspring: population based cohort study"
)

df <- sort(df$V1)
df

# [1] "Association of first trimester prescription opioid use with congenital malformations in the offspring: population based cohort study"       
# [2] "Covid-19 deaths in Africa: prospective systematic postmortem surveillance study"                                                            
# [3] "Food anaphylaxis in the United Kingdom: analysis of national data, 1998-2018"                                                               
# [4] "Hospital admission and mortality rates for non-covid diseases in Denmark during covid-19 pandemic: nationwide population based cohort study"

推荐阅读