如何在 R 中插入 "US$"
How to insert "US$" in R
我想在 datatable
中的数字前插入 US$
。例如,4 美元。我该怎么做?
library(DT)
Test <- structure(list(date2 = structure(c(18808, 18808, 18809, 18810
), class = "Date"), Category = c("FDE", "ABC", "FDE", "ABC"),
coef1 = c(4, 1, 6, 1),coef2 = c(8, 3, 1, 6)), row.names = c(NA, 4L), class = "data.frame")
Test<-Test%>%mutate(Sum = rowSums(across(3:last_col()), na.rm = TRUE))
z<-datatable (Test, options = list(columnDefs = list(list(className = 'dt-center', targets = "_all")),
paging =TRUE,searching = FALSE, pageLength = 10,dom = 'tip',scrollx=T),rownames = FALSE)
您可以为每个数字列粘贴文本 'US $'
。
library(DT)
library(dplyr)
Test<-Test%>%mutate(Sum = rowSums(across(3:last_col()), na.rm = TRUE))
Test <- Test %>% mutate(across(where(is.numeric), ~paste0('US $', .)))
z<-datatable (Test, options = list(columnDefs =
list(list(className = 'dt-center', targets = "_all")),
paging =TRUE,searching = FALSE, pageLength = 10,
dom = 'tip',scrollx=T),rownames = FALSE)
z
我想在 datatable
中的数字前插入 US$
。例如,4 美元。我该怎么做?
library(DT)
Test <- structure(list(date2 = structure(c(18808, 18808, 18809, 18810
), class = "Date"), Category = c("FDE", "ABC", "FDE", "ABC"),
coef1 = c(4, 1, 6, 1),coef2 = c(8, 3, 1, 6)), row.names = c(NA, 4L), class = "data.frame")
Test<-Test%>%mutate(Sum = rowSums(across(3:last_col()), na.rm = TRUE))
z<-datatable (Test, options = list(columnDefs = list(list(className = 'dt-center', targets = "_all")),
paging =TRUE,searching = FALSE, pageLength = 10,dom = 'tip',scrollx=T),rownames = FALSE)
您可以为每个数字列粘贴文本 'US $'
。
library(DT)
library(dplyr)
Test<-Test%>%mutate(Sum = rowSums(across(3:last_col()), na.rm = TRUE))
Test <- Test %>% mutate(across(where(is.numeric), ~paste0('US $', .)))
z<-datatable (Test, options = list(columnDefs =
list(list(className = 'dt-center', targets = "_all")),
paging =TRUE,searching = FALSE, pageLength = 10,
dom = 'tip',scrollx=T),rownames = FALSE)
z