Skip to contents

Convert between different classes

Usage

l2m(l)

m2l(m)

d2m(d)

m2d(m)

l2a(l)

a2l(a)

a2m(a)

m2a(m)

m2ll(m, index = NULL)

Arguments

l

list with x and y coordinates as components

m

matrix of (x; y) coordinates

d

data.frame with two columns

a

array of (x; y) coordinates

index

numeric, the number of coordinates for every slice

Value

the data in the required class

Note

a2m/m2a change, by essence, the dimension of the data. m2ll is used internally to hanle coo and cur in Ldk objects but may be useful elsewhere

See also

Other bridges functions: as_df(), complex, export()

Examples

# matrix/list
wings[1] %>% coo_sample(4) %>%
   m2l() %T>% print %>%        # matrix to list
   l2m()                       # and back
#> $x
#> [1] -0.4933  0.2645  0.0424 -0.1768
#> 
#> $y
#> [1]  0.0130  0.0261 -0.0966  0.0341
#> 
#>            x       y
#> [1,] -0.4933  0.0130
#> [2,]  0.2645  0.0261
#> [3,]  0.0424 -0.0966
#> [4,] -0.1768  0.0341

# data.frame/matrix
wings[1] %>% coo_sample(4) %>%
   m2d() %T>% print %>%        # matrix to data.frame
   d2m                         # and back
#> # A tibble: 4 × 2
#>         x       y
#>     <dbl>   <dbl>
#> 1 -0.493   0.013 
#> 2  0.264   0.0261
#> 3  0.0424 -0.0966
#> 4 -0.177   0.0341
#>            x       y
#> [1,] -0.4933  0.0130
#> [2,]  0.2645  0.0261
#> [3,]  0.0424 -0.0966
#> [4,] -0.1768  0.0341

 # list/array
 wings %>% slice(1:2) %$%
 coo %>% l2a %T>% print %>%    # list to array
 a2l                           # and back
#> , , AN1
#> 
#>          x       y
#> 1  -0.4933  0.0130
#> 2  -0.0777  0.0832
#> 3   0.2231  0.0861
#> 4   0.2641  0.0462
#> 5   0.2645  0.0261
#> 6   0.2471  0.0003
#> 7   0.2311 -0.0228
#> 8   0.2040 -0.0452
#> 9   0.1282 -0.0742
#> 10  0.0424 -0.0966
#> 11 -0.0674 -0.1108
#> 12 -0.4102 -0.0163
#> 13 -0.3140  0.0318
#> 14 -0.1768  0.0341
#> 15  0.0715  0.0509
#> 16 -0.0540  0.0238
#> 17  0.0575 -0.0059
#> 18 -0.1401 -0.0240
#> 
#> , , AN2
#> 
#>          x       y
#> 1  -0.4814  0.0135
#> 2  -0.0058  0.0780
#> 3   0.2345  0.0644
#> 4   0.2460  0.0467
#> 5   0.2487  0.0281
#> 6   0.2430  0.0115
#> 7   0.2316 -0.0039
#> 8   0.1956 -0.0305
#> 9   0.1462 -0.0545
#> 10  0.0483 -0.0866
#> 11 -0.0520 -0.1047
#> 12 -0.4016 -0.0250
#> 13 -0.3868  0.0166
#> 14 -0.1808  0.0229
#> 15  0.0484  0.0405
#> 16 -0.0519  0.0164
#> 17  0.0623 -0.0047
#> 18 -0.1444 -0.0286
#> 
#> [[1]]
#>          x       y
#> 1  -0.4933  0.0130
#> 2  -0.0777  0.0832
#> 3   0.2231  0.0861
#> 4   0.2641  0.0462
#> 5   0.2645  0.0261
#> 6   0.2471  0.0003
#> 7   0.2311 -0.0228
#> 8   0.2040 -0.0452
#> 9   0.1282 -0.0742
#> 10  0.0424 -0.0966
#> 11 -0.0674 -0.1108
#> 12 -0.4102 -0.0163
#> 13 -0.3140  0.0318
#> 14 -0.1768  0.0341
#> 15  0.0715  0.0509
#> 16 -0.0540  0.0238
#> 17  0.0575 -0.0059
#> 18 -0.1401 -0.0240
#> 
#> [[2]]
#>          x       y
#> 1  -0.4814  0.0135
#> 2  -0.0058  0.0780
#> 3   0.2345  0.0644
#> 4   0.2460  0.0467
#> 5   0.2487  0.0281
#> 6   0.2430  0.0115
#> 7   0.2316 -0.0039
#> 8   0.1956 -0.0305
#> 9   0.1462 -0.0545
#> 10  0.0483 -0.0866
#> 11 -0.0520 -0.1047
#> 12 -0.4016 -0.0250
#> 13 -0.3868  0.0166
#> 14 -0.1808  0.0229
#> 15  0.0484  0.0405
#> 16 -0.0519  0.0164
#> 17  0.0623 -0.0047
#> 18 -0.1444 -0.0286
#> 

 # array/matrix
 wings %>% slice(1:2) %$%
 l2a(coo) %>%                  # and array (from a list)
 a2m %T>% print %>%            # to matrix
 m2a                           # and back
#>          x1      x2     x3     x4     x5     x6     x7     x8     x9    x10
#> AN1 -0.4933 -0.0777 0.2231 0.2641 0.2645 0.2471 0.2311 0.2040 0.1282 0.0424
#> AN2 -0.4814 -0.0058 0.2345 0.2460 0.2487 0.2430 0.2316 0.1956 0.1462 0.0483
#>         x11     x12     x13     x14    x15     x16    x17     x18     y1     y2
#> AN1 -0.0674 -0.4102 -0.3140 -0.1768 0.0715 -0.0540 0.0575 -0.1401 0.0130 0.0832
#> AN2 -0.0520 -0.4016 -0.3868 -0.1808 0.0484 -0.0519 0.0623 -0.1444 0.0135 0.0780
#>         y3     y4     y5     y6      y7      y8      y9     y10     y11     y12
#> AN1 0.0861 0.0462 0.0261 0.0003 -0.0228 -0.0452 -0.0742 -0.0966 -0.1108 -0.0163
#> AN2 0.0644 0.0467 0.0281 0.0115 -0.0039 -0.0305 -0.0545 -0.0866 -0.1047 -0.0250
#>        y13    y14    y15    y16     y17     y18
#> AN1 0.0318 0.0341 0.0509 0.0238 -0.0059 -0.0240
#> AN2 0.0166 0.0229 0.0405 0.0164 -0.0047 -0.0286
#> , , AN1
#> 
#>          x       y
#> 1  -0.4933  0.0130
#> 2  -0.0777  0.0832
#> 3   0.2231  0.0861
#> 4   0.2641  0.0462
#> 5   0.2645  0.0261
#> 6   0.2471  0.0003
#> 7   0.2311 -0.0228
#> 8   0.2040 -0.0452
#> 9   0.1282 -0.0742
#> 10  0.0424 -0.0966
#> 11 -0.0674 -0.1108
#> 12 -0.4102 -0.0163
#> 13 -0.3140  0.0318
#> 14 -0.1768  0.0341
#> 15  0.0715  0.0509
#> 16 -0.0540  0.0238
#> 17  0.0575 -0.0059
#> 18 -0.1401 -0.0240
#> 
#> , , AN2
#> 
#>          x       y
#> 1  -0.4814  0.0135
#> 2  -0.0058  0.0780
#> 3   0.2345  0.0644
#> 4   0.2460  0.0467
#> 5   0.2487  0.0281
#> 6   0.2430  0.0115
#> 7   0.2316 -0.0039
#> 8   0.1956 -0.0305
#> 9   0.1462 -0.0545
#> 10  0.0483 -0.0866
#> 11 -0.0520 -0.1047
#> 12 -0.4016 -0.0250
#> 13 -0.3868  0.0166
#> 14 -0.1808  0.0229
#> 15  0.0484  0.0405
#> 16 -0.0519  0.0164
#> 17  0.0623 -0.0047
#> 18 -0.1444 -0.0286
#> 

 # m2ll
m2ll(wings[1], c(6, 4, 3, 5)) # grab slices and coordinates
#> [[1]]
#>         [,1]   [,2]
#> [1,] -0.4933 0.0130
#> [2,] -0.0777 0.0832
#> [3,]  0.2231 0.0861
#> [4,]  0.2641 0.0462
#> [5,]  0.2645 0.0261
#> [6,]  0.2471 0.0003
#> 
#> [[2]]
#>        [,1]    [,2]
#> [1,] 0.2311 -0.0228
#> [2,] 0.2040 -0.0452
#> [3,] 0.1282 -0.0742
#> [4,] 0.0424 -0.0966
#> 
#> [[3]]
#>         [,1]    [,2]
#> [1,] -0.0674 -0.1108
#> [2,] -0.4102 -0.0163
#> [3,] -0.3140  0.0318
#> 
#> [[4]]
#>         [,1]    [,2]
#> [1,] -0.1768  0.0341
#> [2,]  0.0715  0.0509
#> [3,] -0.0540  0.0238
#> [4,]  0.0575 -0.0059
#> [5,] -0.1401 -0.0240
#>