簡體   English   中英

在 R 中合並表格中的表格

[英]Merge tables in formattable in R

有沒有辦法在 R 中以 formatttable 格式組合這兩個表? 我想保留最終表格數據中的迷你圖:

test1<-structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L), .Label = c("John", "Mary"), class = "factor"), 
    year = c(2021L, 2021L, 2021L, 2021L, 2021L, 2021L, 2021L, 
    2021L, 2021L, 2021L, 2021L, 2021L), week = c(1L, 2L, 3L, 
    4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), Total = c(3L, 2L, 0L, 
    0L, 1L, 0L, 3L, 2L, 0L, 0L, 1L, 0L)), class = "data.frame", row.names = c(NA, 
-12L))

data <- structure(list(Name = structure(2:1, .Label = c("John", "Mary"
), class = "factor"), Total_per_name = c(50L, 100L)), class = "data.frame", row.names = c(NA, 
-2L))

My code
test1 %>% 
      group_by(Name) %>%
      summarise("Weekly_trend" = spk_chr(Total)) %>%
      formattable() %>%
      as.datatable() %>%
      spk_add_deps()

summarise后加入

library(dplyr)
library(formattable)
library(sparkline)
test1 %>% 
  group_by(Name) %>%
  summarise("Weekly_trend" = spk_chr(Total))  %>%
  left_join(data) %>%
  formattable() %>%
  as.datatable() %>%
  spk_add_deps()

-輸出

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM