knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(texblocks) library(texPreview)
tex_opts$set(returnType = 'html') tex_opts$append(list(cleanup='tex'))
can be with or without tabular wrapper
x <- '\\begin{tabular}{l|cccccccccc} number of flips& 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 \\\\ number of heads& 8 & 8 & 9 & 10 & 10 & 10 & 10 & 10 & 10 & 11 \\\\\\hline proportion& .73 & .67 & .69 & .71 & .67 & .63 & .59 & .56 & .53 & .55 \\end{tabular}'
x <- 'number of flips& 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 \\\\ number of heads& 8 & 8 & 9 & 10 & 10 & 10 & 10 & 10 & 10 & 11 \\\\\\hline proportion& .73 & .67 & .69 & .71 & .67 & .63 & .59 & .56 & .53 & .55'
x <- x%>%as.tb()
x%>% as.data.frame()
Use type.convert() to set column class in matrix
x%>% as.data.frame(convert = TRUE)
x%>% as.data.frame(convert = TRUE)%>% tidyr::gather(col,val,-1)
x%>% t()%>% as.data.frame()
x%>% t()%>% hline()%>% tabular(align = '|c|c|c|')%>% texPreview::tex_preview()
mat <- Matrix::bdiag( Matrix::Diagonal(2), matrix(1:3, 3,4), diag(3:2) ) mat
x <- mat %>% as.tb() x
extract subset of the texblock by index
x%>%crop(1:2,1:2) # extract smaller tb from rows 1:2 columns 1:2 x%>%crop(3:5,3:6) # extract smaller tb from rows 3:5 columns 3:6 x%>%crop(6:7,7:8) # extract smaller tb from rows 6:7 columns 7:8
extract subsets of the texblock using lists , i.e. blocks of tb's by blocks of the matrix
x1 <- x%>% harvest( list(1:2,3:5,6:7), list(1:2,3:6,7:8) ) x1
Back to the original Sparse Matrix
x1%>% purrr::map(as.matrix)%>% #convert back to list of matrices Matrix::bdiag() # convert back to original block matrix
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.