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

发布于 2024-08-24 00:24:01 字数 1022 浏览 10 评论 0原文

我有一些数据(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 (或其他方式吗?)

I've got some data (the output of a ddply function) that I want to present in an xtable for use somewhere else.

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")

which gives me the table in html format. However, I want to Merge together the content of the RUNID and ANALYTEINDEX columns vertically where the values are the same. Anyone know how to do that via xtable (or some other way ?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2024-08-31 00:24:01

我会“清理”原始数据框,用 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)

I would "clean up" the original data frame replacing the values that are equal to the previous value by NA. xtable will render these missing values as empty spaces. This will look good if you don't have horizontal border lines.

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

Now we can apply this function to the columns that you want cleaned up:

clean.cols <- c( "RUNID", "ANALYTEINDEX")
calqc_table[clean.cols] <- lapply(calqc_table[clean.cols], cleanf)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文