gpt4 book ai didi

r - 你能在 R 的 xtable 中合并单元格吗

转载 作者:行者123 更新时间:2023-12-01 13:07:02 25 4
gpt4 key购买 nike

我有一些数据(ddply 函数的输出),我想在 xtable 中显示以供在其他地方使用。

calqc_table<-structure(list(RUNID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L), ANALYTEINDEX = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), ID = structure(1:11, .Label = c("Cal A", "Cal B", "Cal C",
"Cal D", "Cal E", "Cal F", "Cal G", "Cal H", "Cal High", "Cal Low",
"Cal Mid"), class = "factor"), mean_conc = c(200.619459644855,
158.264703128903, 102.469121407733, 50.3551544728544, 9.88296440865076,
4.41727762501703, 2.53494715706024, 1.00602831741361, 199.065054555735,
2.48063347296935, 50.1499780776199), sd_conc = c(2.3275711264554,
NA, NA, NA, NA, NA, NA, 0.101636943231162, 0, 0, 0), nrow = c(3,
1, 1, 1, 1, 1, 1, 3, 2, 2, 2)), .Names = c("RUNID", "ANALYTEINDEX",
"ID", "mean_conc", "sd_conc", "nrow"), row.names = c(NA, -11L
), class = "data.frame")
calqc_xtable<-xtable(calqc_table)
print(calqc_xtable,type="html")

这给了我 html 格式的表格。但是,我想将值相同的 RUNID 和 ANALYTEINDEX 列的内容垂直合并在一起。任何人都知道如何通过 xtable(或其他方式?)做到这一点

最佳答案

我会“清理”原始数据框,用 NA 替换与先前值相等的值。 xtable 会将这些缺失值呈现为空格。如果您没有水平边框线,这会很好看。

cleanf <- function(x){ 
oldx <- c(FALSE, x[-1]==x[-length(x)]) # is the value equal to the previous?
res <- x
res[oldx] <- NA
res}

现在我们可以将此函数应用于您要清理的列:

clean.cols <- c( "RUNID", "ANALYTEINDEX")
calqc_table[clean.cols] <- lapply(calqc_table[clean.cols], cleanf)

关于r - 你能在 R 的 xtable 中合并单元格吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2379701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com