我有两个像这样的数据框,里面充满了求职者的信息:
Scores<-structure(list(Name = c("John Smith", "Jane Doe",
"John Doe", "Jan Jenkins", "Lauren John", "Jennifer Patty",
"Zachary Gala"), `Applicant Name` = c(1, 18, 5, 6, 3, 4, 2),
`Sum-100` = c(75, 85, 97, 53, 61, 31, 85), `Edu.-20` = c(12,
19, 20, 10, 14, 8, 18), `Personality-15` = c(10, 14, 15,
8, 8, 7, 12), `Verbal-15` = c(12, 12, 14, 7, 6, 6, 13), `Maturity-15` = c(14,
11, 15, 8, 8, 5, 13), `Research-15` = c(13, 10, 14, 10, 13,
4, 14), `Intellect-15` = c(16, 19, 19, 10, 11, 1, 15), `LOR-10` = c(NaN,
9, 3, 8, 6, 4, NaN), `PS-10` = c(NaN, 8, 3, 8, 5, 4, NaN)), row.names = c(NA,
-7L), groups = structure(list(Name = c("John Smith", "Jane Doe",
"John Doe", "Jan Jenkins", "Jennifer Patty", "Jennifer Patty",
"Zachary Gala"), .rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L,
7L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), row.names = c(NA, 7L), class = c("tbl_df", "tbl",
"data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
Comments<-structure(list(`Applicant Name` = c(1, 1, 2, 2, 3, 2, 2, 3, 3,
4, 5, 6, 3, 3, 1, 1, 18), Name = c("John Smith", "John Smith",
"Zachary Gala", "Zachary Gala", "Lauren John", "Zachary Gala",
"Zachary Gala", "Lauren John", "Lauren John",
"Jennifer Patty", "John Doe", "Jan Jenkins", "Lauren John",
"Lauren John", "John Smith", "John Smith",
"Jane Doe"), Overall = c("overall good and bla bla bla this is a very long comment because I want to see how it works etc. etc. bla",
"cant do it", "breathtaking", "fdwdf wfew", "joke was funny",
"Interesting person", "asdfd asdasf dasjlfoeiwna osdnkdasjbfiabdk hfhajh dsfklhdsakl hfawei uhdk jashfiaw ulhfk jldbkla hbvliub",
"Dumb", "sfdgsv", "do not take this person", "incredible opportunity for us",
"medium plus", "bla", "goao", "dfg", "ffohfosfdosfdifof", "Silly"
)), row.names = c(NA, -17L), class = c("tbl_df", "tbl", "data.frame"
))我正在汇总所有这些数据,并在pdf中显示有关它的图表,我可能会打印出来,并亲自交给一群将审查候选人的人。有一个关于每个候选人的部分,看起来像这样:

我刚遇到一位审稿人,他问我是否可以重新组织文档,这样分数较高的申请者就可以在文档顶部附近看到他们的部分。有没有办法用代码做到这一点?值得一提的是,我实际上还没有他们的分数和数据(将在最后一秒从redcap数据库中获得),所以理想情况下,当我获得原始数据时,我可以编写代码来自动移动所有数据。在物理上重新组织他们的部分在pdf中的位置。我可以想象在这段代码中有一些过滤器:
kable(School%>%filter(applicant_name=="2")%>%select(-applicant_name))%>%
kable_paper("hover", full_width = F)这将过滤到具有“第二好”分数或其他东西的人,但我如何重新组织申请者去了哪里的照片?章节标题里写的是什么名字?这有可能吗?
发布于 2020-12-14 21:00:11
您可以首先根据感兴趣的分数排列tibble,然后在循环中使用\section{} (LaTeX)生成动态部分。
假设kableExtra-tables的处理方式与knitr::kable的处理方式相同,那么这些方法就可以实现它
---
output: pdf_document
---
```{r, results='asis', echo=FALSE, message=FALSE, warning=FALSE}库(Dplyr)
库(Knitr)
库(KableExtra)
分数<-结构(list(Name= c("John Smith","Jane Doe",
“无名氏”,“简·詹金斯”,“劳伦·约翰”,“詹妮弗·帕蒂”
"Zachary Gala"),Applicant Name = c(1,18,5,6,3,4,2),
`Sum-100` = c(75, 85, 97, 53, 61, 31, 85), `Edu.-20` = c(12, 19, 20, 10, 14, 8, 18), `Personality-15` = c(10, 14, 15, 8, 8, 7, 12), `Verbal-15` = c(12, 12, 14, 7, 6, 6, 13), `Maturity-15` = c(14, 11, 15, 8, 8, 5, 13), `Research-15` = c(13, 10, 14, 10, 13, 4, 14), `Intellect-15` = c(16, 19, 19, 10, 11, 1, 15), `LOR-10` = c(NaN, 9, 3, 8, 6, 4, NaN), `PS-10` = c(NaN, 8, 3, 8, 5, 4, NaN)), row.names = c(NA, -7L),组=结构(列表(名称= c("John Smith","Jane Doe",
“无名氏”,“简·詹金斯”,“詹妮弗·帕蒂”,“詹妮弗·帕蒂”
"Zachary Gala"),.rows =结构(list(1L,2L,3L,4L,5L,6L,
7L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", “list”)),row.names = c(NA,7L),class = c("tbl_df",“TB1”,
"data.frame"),.drop =真),class = c("grouped_df","tbl_df",
"tbl","data.frame"))
```{r, results='asis', echo=FALSE}#按Sum-100列降序排列tibble。
arrangedScores <-给%>%评分
排列(描述(Sum-100))
#按降序提取要在for循环中迭代的名称
arrangedNames <- arrangedScores$Name
#取消注释以包含图片
#arrangedScores$img <- "example_image.png“
对于(arrangedNames中的i){
tableFrame <- arrangedScores %>%
dplyr::filter(Name == i)#创建带名称和分数的分节表头
cat(paste0("\section{",i,". Score:",tableFrame$Sum-100 ),"}")
#取消注释以包含图片
#cat("
")
#打印表。需要print()来在循环中打印kable,ref
#https://bookdown.org/yihui/rmarkdown-cookbook/kable.html#generate-multiple-tables-from-a-for-loop
打印(kable(TableFrame))
#删除此选项不会为每个应用程序生成新页面
cat("\newpage")
}
https://stackoverflow.com/questions/65288125
复制相似问题