【发布时间】:2019-01-20 20:14:08
【问题描述】:
我有一个响应式数据框如下:
Apr 2017 May 2017 Jun 2017 Jul 2017 Aug 2017 Sep 2017
zz 0.1937571 0.1840005 0.1807256 0.1959589 0.2039463 0.2016886
aa 0.3518203 0.3634578 0.3670747 0.3676495 0.3680581 0.3657724
bb 0.10651308 0.11548379 0.11572389 0.11272168 0.11361587 0.11503638
cc 0.2481513 0.2579199 0.2623222 0.2673914 0.2579430 0.2550686
dd 0.06641069 0.06741159 0.07305105 0.07373854 0.07043972 0.07304338
我正在尝试根据值设置整个表格的样式(类似于此,eg3)。 下面是我的代码:
brks <- reactive({
quantile(intrc_pattern_re(), probs = seq(0, 1, 0.25), na.rm = TRUE)
})
clrs <- reactive({
round(seq(255, 40, length.out = length(brks()) + 1), 0) %>%
paste0("rgb(255,", ., ",", ., ")")
})
intrc_pattern_reshape <- reactive ({
datatable(intrc_pattern_re(),
options = list(searching = FALSE,
pageLength = 15,
lengthChange = FALSE)
) %>%
formatPercentage(colnames(intrc_pattern_re()), 2) %>%
formatStyle(names(intrc_pattern_re()),
backgroundColor = styleInterval(brks(), clrs()))
})
但是当我这样做时,我收到以下错误:non-numeric argument to binary operator
谁能告诉我我做错了什么?谢谢你。 dput(df,"") 的输出
structure(list(`Apr 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.06641069",
"0.10651308", "0.1937571", "0.2481513", "0.3090870", "0.3518203",
"0.4697810", "Apr 2017"), class = "factor"), `May 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.06741159",
"0.11548379", "0.1840005", "0.2579199", "0.3043959", "0.3634578",
"0.4719425", "May 2017"), class = "factor"), `Jun 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.07305105",
"0.11572389", "0.1807256", "0.2623222", "0.3030102", "0.3670747",
"0.4766237", "Jun 2017"), class = "factor"), `Jul 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.07373854",
"0.11272168", "0.1959589", "0.2673914", "0.2984132", "0.3676495",
"0.4759238", "Jul 2017"), class = "factor"), `Aug 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.07043972",
"0.11361587", "0.2039463", "0.2579430", "0.2970350", "0.3680581",
"0.4828409", "Aug 2017"), class = "factor"), `Sep 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.07304338",
"0.11503638", "0.2016886", "0.2550686", "0.2998945", "0.3657724",
"0.4909182", "Sep 2017"), class = "factor"), `Oct 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 2L, `cc` = 4L,
dd = 1L, Premium = 7L, `ff` = 5L), .Label = c("0.07651393",
"0.11219458", "0.2025043", "0.2479362", "0.2866641", "0.3673334",
"0.5121613", "Oct 2017"), class = "factor"), `Nov 2017` = structure(c(`zz` = 3L,
aa = 6L, `bb` = 1L, `cc` = 4L,
dd = 2L, Premium = 7L, `ff` = 5L), .Label = c("0.10724728",
"0.15016708", "0.1857769", "0.2280702", "0.2691103", "0.3417920",
"0.4948308", "Nov 2017"), class = "factor"), `Dec 2017` = structure(c(`zz` = 2L,
aa = 5L, `bb` = 1L, `cc` = 3L,
dd = 6L, Premium = 7L, `ff` = 4L), .Label = c("0.08775835",
"0.1659323", "0.1945492", "0.2304338", "0.2958437", "0.29888712",
"0.4493300", "Dec 2017"), class = "factor"), `Jan 2018` = structure(c(`zz` = 2L,
aa = 5L, `bb` = 1L, `cc` = 3L,
dd = 6L, Premium = 7L, `ff` = 4L), .Label = c("0.08016616",
"0.1565603", "0.1753247", "0.2134740", "0.2811306", "0.34148205",
"0.4315794", "Jan 2018"), class = "factor")), row.names = c("zz",
"aa", "bb", "cc", "dd",
"Premium", "ff"), class = "data.frame")
【问题讨论】:
-
您的代码中如何引用这些数据?
intrc_pattern_re()是否返回您显示的数据框? -
@divibisan intrc_pattern() 是一个错误。 intrc_pattern_re() 返回我上面提到的结构的df。
-
您撤回接受的答案了吗?你还有这个问题吗?
-
@divibisan 我实际上认为我发送的是 df 而不是 df 的专栏以获得休息时间。我从正确的 df 传递了正确的列,它对我来说效果很好。谢谢你的回答。