简体   繁体   English

如何删除/更改 flextable 中的小数和值

[英]How to remove/change decimal sum value in flextable

I managed to create a flextable based on the below code.我设法根据以下代码创建了一个弹性表。 The data that is being used in opleiding1 through 4 looks a bit like this: 0, 0, 1, 7, 3, 7, 0 opleiding1 到 4 中使用的数据看起来有点像这样:0, 0, 1, 7, 3, 7, 0

t7 <- data.frame(df$opleiding.1.[df$startvraag=="Ja"],
                 df$opleiding.2.[df$startvraag=="Ja"],
                 df$opleiding.3.[df$startvraag=="Ja"],
                 df$opleiding.4.[df$startvraag=="Ja"]
)

t7 <- data.frame(aantal=(apply(t7, 2, sum))) %>% round(digits = 0)
rownames(t7) <- c("hbo, universitair", "mbo, vwo, havo", "vmbo/mavo", "onbekend")
t7

Creating a flextable with the following code:使用以下代码创建弹性表:

t7 <- xtable(t7)

ft7 <- t7 %>% xtable_to_flextable() %>% 
  fontsize(part = "header", size = 20) %>%
  fontsize(part = "body", size = 18) %>%
  align_text_col(align = "left") %>% 
  align_nottext_col(align = "center") %>%
  width(width = 2.3) %>%
  width(j = 1, width = 2.0) %>%
  height_all(height = .5) %>%
  border_inner(border = std_border) %>% 
  font(fontname = "Open Sans") %>%
  color(part = "header", color = d) %>% 
ft7

This gives me a flextable which is just as I want it except for the decimal which are shown here .这给了我一个 flextable,它是我想要的,除了这里显示的小数。 I've looked for possible solutions but nothing seems to work.我一直在寻找可能的解决方案,但似乎没有任何效果。 It looks like the decimal is added when converting the table to an flextable.将表格转换为弹性表格时,似乎添加了小数点。 When I run the previous code (mentions on top) it does not return with any decimals as shown here .当我运行前面的代码(上面提到)时,它不会返回任何小数,如此处所示 Hope someone can help me sort this.希望有人可以帮我解决这个问题。

I think that is because your aantal column's type is double , meaning it is holding real values.我认为这是因为您的aantal列的类型是double ,这意味着它具有真实值。 You can change it's type to integer as you create the data.frame.您可以在创建data.frame时将其类型更改为 integer。

Try this尝试这个

t7 <- data.frame(aantal=(apply(t7, 2, sum))) %>% 
    round(digits = 0) %>%
    mutate(aantal = as.integer(aantal))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM