How to show Greek letters as matrix tree names

I am wondering how to set the names of the sockets of a matrix, including Greek letter expressions in R. I use an expression, but it seems to be inoperative. Here is my code below.

b.summary = matrix(0, 8, 6) colnames(b.summary)= c("Min.", "1st Qu.", "Median", "Mean","3rd Qu", "Max." ) rownames(b.summary)= c(expression(paste(tau, "=1", sep="")),expression(paste(sigma^2, "=1", sep="")), expression(paste(tau, "=5",sep="")), expression(paste(sigma^2, "=0.2",sep="")), expression(paste(tau, "=16", sep="")), expression(paste(sigma^2, "=0.0625",sep="")), expression(paste(tau, "1/2.25", sep="")),expression( paste(sigma^2, "=2.25", sep="")) ) 

When I type b.summary, the following are the names of the growths:

 paste(tau, "=1", sep = "") 

instead of latex expression.

The reason I need Greek letters is because I use knitr to create a dynamic document. I want to show the result of this matrix directly, and not create a table by manually typing all the elements of the matrix using the expression \ Sexpr {}. The full snippet of code in the bookie

 <<coverage.b.summary, eval=TRUE, echo=FALSE>>= b.summary = matrix(runif(48), 8, 6) colnames(b.summary)= c("Min.", "1st Qu.", "Median", "Mean","3rd Qu", "Max." ) rownames(b.summary)= labels(expression(paste(tau, "=1", sep="")),expression(paste(sigma^2, "=1", sep="")), expression(paste(tau, "=5",sep="")), expression(paste(sigma^2, "=0.2",sep="")), expression(paste(tau, "=16", sep="")), expression(paste(sigma^2, "=0.0625",sep="")), expression(paste(tau, "=1/2.25", sep="")),expression( paste(sigma^2, "=2.25", sep="")) ) b.summary @ 

Thank you for your help!

+6
source share
2 answers

This is the best I can do when limiting the use of the matrix. Rones cannot be R expression classified objects. I create a named vector called "Greeks" and pull Unicode values ​​out of it, using names, and then using the reprocessing of the arguments to indicate alternating strings with tau and sigma ^ 2. (Failure to use expression tools cannot have sub-scripting in matrix row names.)

 greeks=c(alpha='\u03b1', tau='\u03c4', sigma='\u03c3', beta='\u03b2', gamma='\u03b3') b.summary = matrix(0, 8, 6) colnames(b.summary)= c("Min.", "1st Qu.", "Median", "Mean","3rd Qu", "Max." ) rownames(b.summary)= paste0(c( greeks['tau'], paste0(greeks['sigma'],"^2") ), c("=1","=1", "=5", "=0.2", "=16", "=0.0625", "=2.25", "=2.25") ) > b.summary Min. 1st Qu. Median Mean 3rd Qu Max. τ=1 0 0 0 0 0 0 σ^2=1 0 0 0 0 0 0 τ=5 0 0 0 0 0 0 σ^2=0.2 0 0 0 0 0 0 τ=16 0 0 0 0 0 0 σ^2=0.0625 0 0 0 0 0 0 τ=2.25 0 0 0 0 0 0 σ^2=2.25 0 0 0 0 0 0 
+5
source

Tweaking @ 42- solution (this should be a comment, but the answer has better code formatting):

 greeks = c(alpha='\u03b1', tau='\u03c4', sigma='\u03c3', sigmaSq='\u03c3\u00B2', beta='\u03b2', gamma='\u03b3') b.summary = matrix(0, 8, 6) colnames(b.summary) = c("Min.", "1st Qu.", "Median", "Mean","3rd Qu", "Max.") p1 = c(greeks['tau'], greeks['sigmaSq']) p2 = c("1","1", "5", "0.2", "16", "0.0625", "2.25", "2.25") rownames(b.summary) = paste(p1, p2, sep="=") b.summary 

produces the following

  Min. 1st Qu. Median Mean 3rd Qu Max. τ=1 0 0 0 0 0 0 σ²=1 0 0 0 0 0 0 τ=5 0 0 0 0 0 0 σ²=0.2 0 0 0 0 0 0 τ=16 0 0 0 0 0 0 σ²=0.0625 0 0 0 0 0 0 τ=2.25 0 0 0 0 0 0 σ²=2.25 0 0 0 0 0 0 

In my particular use case, I am KnitR'ing the "kable" of dispersion inflation coefficients and sd inflation coefficients for the mtcars :

 cars.vif = rbind( t(vif(cars.model)[,1]), t(sqrt(vif(cars.model))[,1]) ) rownames(cars.vif) = c("\u03c3", "\u03c3\u00B2") kable(cars.vif) 

Rownames with Greek Character and Superscript

This requires xelatex and a font containing σ ie Arial

+2
source

Source: https://habr.com/ru/post/983828/


All Articles