can be with or without tabular wrapper
x%>%
as.data.frame()
#> # A tibble: 3 x 11
#> `1` `2` `3` `4` `5` `6` `7` `8` `9` `10` `11`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 number … " 11 " " 12 " " 13 " " 14 " " 15 " " 16… " 17… " 18… " 19… " 20…
#> 2 number … " 8 " " 8 " " 9 " " 10 " " 10 " " 10… " 10… " 10… " 10… " 11…
#> 3 proport… " .73… " .67… " .69… " .71… " .67… " .… " .5… " .5… " .5… " .5…
Use type.convert()
to set column class in matrix
x%>%
as.data.frame(convert = TRUE)
#> # A tibble: 3 x 11
#> `1` `2` `3` `4` `5` `6` `7` `8` `9` `10` `11`
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 number of fl… 11 12 13 14 15 16 17 18 19 20
#> 2 number of he… 8 8 9 10 10 10 10 10 10 11
#> 3 proportion 0.73 0.67 0.69 0.71 0.67 0.63 0.59 0.56 0.53 0.55
x%>%
as.data.frame(convert = TRUE)%>%
tidyr::gather(col,val,-1)
#> # A tibble: 30 x 3
#> `1` col val
#> <chr> <chr> <dbl>
#> 1 number of flips 2 11
#> 2 number of heads 2 8
#> 3 proportion 2 0.73
#> 4 number of flips 3 12
#> 5 number of heads 3 8
#> 6 proportion 3 0.67
#> 7 number of flips 4 13
#> 8 number of heads 4 9
#> 9 proportion 4 0.69
#> 10 number of flips 5 14
#> # … with 20 more rows
x%>%
t()%>%
as.data.frame()
#> # A tibble: 11 x 3
#> `1` `2` `3`
#> <chr> <chr> <chr>
#> 1 number of flips number of heads proportion
#> 2 " 11 " " 8 " " .73 "
#> 3 " 12 " " 8 " " .67 "
#> 4 " 13 " " 9 " " .69 "
#> 5 " 14 " " 10 " " .71 "
#> 6 " 15 " " 10 " " .67 "
#> 7 " 16 " " 10 " " .63 "
#> 8 " 17 " " 10 " " .59 "
#> 9 " 18 " " 10 " " .56 "
#> 10 " 19 " " 10 " " .53 "
#> 11 " 20 " " 11 " " .55"
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
#> [[1]]
#> 1& \\
#> &1\\
#>
#> [[2]]
#> 1&1&1&1\\
#> 2&2&2&2\\
#> 3&3&3&3\\
#>
#> [[3]]
#> 3& \\
#> &2\\
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
#> 7 x 8 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . . . . . .
#> [2,] . 1 . . . . . .
#> [3,] . . 1 1 1 1 . .
#> [4,] . . 2 2 2 2 . .
#> [5,] . . 3 3 3 3 . .
#> [6,] . . . . . . 3 .
#> [7,] . . . . . . . 2