2017-03-08 163 views
0
R中的風格數據表

我所描述的here,我得到以下錯誤的代碼無法閃亮

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE) 

enter image description here

我用努力風格ELISA數據(數字)表遵循網頁中描述的代碼。有人能指出我在這裏錯過了什麼嗎?

df <- matrix(nrow=8, ncol=12) 
for (i in 1:8) { 
    for (j in 1:12) 
    df[i,j] <- format(as.numeric(elisa65[i,j])/as.numeric(elisa74[i,j]),digits = 4) 
} 

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE) 
clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) 
       %>% {paste0("rgb(255,", ., ",", ., ")")} 

DT::datatable(df) %>% formatStyle(names(df), backgroundColor = styleInterval(brks, clrs)) 

ELISA Data Table

+0

'format'返回一個字符串,S o你需要quantiling – HubertL

+0

由於之前使用'as.numeric'!這很有幫助。 – RanonKahn

回答

1

我注意到在你的代碼的兩個問題:

  1. clrs是一個字符,你實際上並沒有評估調用 rgb
  2. dfmatrix和您在 代碼中將其視爲data.frame上述

嘗試了這一點

require(dplyr) 
require(DT) 
df <- matrix(rnorm(8 * 12), nrow=8, ncol=12) 

brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE) 
clrs <- sapply(round(seq(255, 40, length.out = length(brks) + 1), 0), 
       function(x) rgb(255, x, x, maxColorValue = 255)) 

df <- data.frame(df) 
datatable(df) %>% formatStyle(names(df), backgroundColor = styleInterval(brks, clrs))