[英]Add sign (*) to values in a table that meet a condition (greater than) in an R Notebook
我想在R Notebook中滿足條件的值上添加標記。 我可以使用knitr html表,但常規表也可以。
該表總結了一個結果,我想強調一下那些大於分析的置信度(0.95)的結果。 以粗體顯示值可以,在數字后面也可以添加“ *” ...
我一直在嘗試...但是我無法做到...除了在所有單元格之間循環(for循環)並在滿足條件的情況下粘貼“ *”。 但是應該有更好的方法! 謝謝!
一個例子:
example <- structure(list(Period = structure(1:3, .Label = c("period1",
"period2", "period3", "period4", "period5", "period6", "period7"
), class = "factor"), Amphibians = c(1, 0.821782178217822, 0.891089108910891
), Aves = c(1, 0.811881188118812, 0.316831683168317)), .Names = c("Period",
"Amphibians", "Aves"), row.names = c(NA, 3L), class = "data.frame")
這是將*
添加到kable
的一種方法。 您需要一個數字版本以與0.95進行比較,並需要一個字符版本以粘貼*
。 同樣,對於這種事情,因素也是可怕的。
example_temp <- apply(example,2,as.numeric)
example <- apply(example,2,as.character)
example <- as.data.frame(example,stringsAsFactors=FALSE)
example[example_temp>.95&!is.na(example_temp)] <-paste(example[example_temp>.95&!is.na(example_temp)] ,"*")
kable(example)
|Period |Amphibians |Aves |
|:-------|:-----------|:-----------|
|period1 |1.0000000 * |1.0000000 * |
|period2 |0.8217822 |0.8118812 |
|period3 |0.8910891 |0.3168317 |
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.