dwww Home | Show directory contents | Find package

R version 2.15.3 (2013-03-01) -- "Security Blanket"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ## load miscTools package
> library( "miscTools" )
> 
> ## create a matrix
> m <- matrix( 1:9, 3 )
> 
> # insert rows
> print( insertRow( m, 1, 10:12 ) )
     [,1] [,2] [,3]
[1,]   10   11   12
[2,]    1    4    7
[3,]    2    5    8
[4,]    3    6    9
> print( insertRow( m, 2, 10:12 ) )
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]   10   11   12
[3,]    2    5    8
[4,]    3    6    9
> print( insertRow( m, 3, 10:12 ) )
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]   10   11   12
[4,]    3    6    9
> print( insertRow( m, 4, 10:12 ) )
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
[4,]   10   11   12
> 
> # insert columns
> print( insertCol( m, 1, 10:12 ) )
     [,1] [,2] [,3] [,4]
[1,]   10    1    4    7
[2,]   11    2    5    8
[3,]   12    3    6    9
> print( insertCol( m, 2, 10:12 ) )
     [,1] [,2] [,3] [,4]
[1,]    1   10    4    7
[2,]    2   11    5    8
[3,]    3   12    6    9
> print( insertCol( m, 3, 10:12 ) )
     [,1] [,2] [,3] [,4]
[1,]    1    4   10    7
[2,]    2    5   11    8
[3,]    3    6   12    9
> print( insertCol( m, 4, 10:12 ) )
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> 
> # insert rows with name
> print( insertRow( m, 1, 10:12, "R0" ) )
   [,1] [,2] [,3]
R0   10   11   12
      1    4    7
      2    5    8
      3    6    9
> print( insertRow( m, 2, 10:12, "R1a" ) )
    [,1] [,2] [,3]
       1    4    7
R1a   10   11   12
       2    5    8
       3    6    9
> print( insertRow( m, 3, 10:12, "R2a" ) )
    [,1] [,2] [,3]
       1    4    7
       2    5    8
R2a   10   11   12
       3    6    9
> print( insertRow( m, 4, 10:12, "R4" ) )
   [,1] [,2] [,3]
      1    4    7
      2    5    8
      3    6    9
R4   10   11   12
> 
> # insert columns with name
> print( insertCol( m, 1, 10:12, "C0" ) )
     C0      
[1,] 10 1 4 7
[2,] 11 2 5 8
[3,] 12 3 6 9
> print( insertCol( m, 2, 10:12, "C1a" ) )
       C1a    
[1,] 1  10 4 7
[2,] 2  11 5 8
[3,] 3  12 6 9
> print( insertCol( m, 3, 10:12, "C2a" ) )
         C2a  
[1,] 1 4  10 7
[2,] 2 5  11 8
[3,] 3 6  12 9
> print( insertCol( m, 4, 10:12, "C4" ) )
           C4
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
> 
> ## add row names and column names
> rownames( m ) <- c( "R1", "R2", "R3" )
> colnames( m ) <- c( "C1", "C2", "C3" )
> 
> # insert rows
> print( insertRow( m, 1, 10:12 ) )
   C1 C2 C3
   10 11 12
R1  1  4  7
R2  2  5  8
R3  3  6  9
> print( insertRow( m, 2, 10:12 ) )
   C1 C2 C3
R1  1  4  7
   10 11 12
R2  2  5  8
R3  3  6  9
> print( insertRow( m, 3, 10:12 ) )
   C1 C2 C3
R1  1  4  7
R2  2  5  8
   10 11 12
R3  3  6  9
> print( insertRow( m, 4, 10:12 ) )
   C1 C2 C3
R1  1  4  7
R2  2  5  8
R3  3  6  9
   10 11 12
> 
> # insert columns
> print( insertCol( m, 1, 10:12 ) )
      C1 C2 C3
R1 10  1  4  7
R2 11  2  5  8
R3 12  3  6  9
> print( insertCol( m, 2, 10:12 ) )
   C1    C2 C3
R1  1 10  4  7
R2  2 11  5  8
R3  3 12  6  9
> print( insertCol( m, 3, 10:12 ) )
   C1 C2    C3
R1  1  4 10  7
R2  2  5 11  8
R3  3  6 12  9
> print( insertCol( m, 4, 10:12 ) )
   C1 C2 C3   
R1  1  4  7 10
R2  2  5  8 11
R3  3  6  9 12
> 
> # insert rows with name
> print( insertRow( m, 1, 10:12, "R0" ) )
   C1 C2 C3
R0 10 11 12
R1  1  4  7
R2  2  5  8
R3  3  6  9
> print( insertRow( m, 2, 10:12, "R1a" ) )
    C1 C2 C3
R1   1  4  7
R1a 10 11 12
R2   2  5  8
R3   3  6  9
> print( insertRow( m, 3, 10:12, "R2a" ) )
    C1 C2 C3
R1   1  4  7
R2   2  5  8
R2a 10 11 12
R3   3  6  9
> print( insertRow( m, 4, 10:12, "R4" ) )
   C1 C2 C3
R1  1  4  7
R2  2  5  8
R3  3  6  9
R4 10 11 12
> 
> # insert columns with name
> print( insertCol( m, 1, 10:12, "C0" ) )
   C0 C1 C2 C3
R1 10  1  4  7
R2 11  2  5  8
R3 12  3  6  9
> print( insertCol( m, 2, 10:12, "C1a" ) )
   C1 C1a C2 C3
R1  1  10  4  7
R2  2  11  5  8
R3  3  12  6  9
> print( insertCol( m, 3, 10:12, "C2a" ) )
   C1 C2 C2a C3
R1  1  4  10  7
R2  2  5  11  8
R3  3  6  12  9
> print( insertCol( m, 4, 10:12, "C4" ) )
   C1 C2 C3 C4
R1  1  4  7 10
R2  2  5  8 11
R3  3  6  9 12
> 
> # insert a row to a single-column matrix (example provided by Max Gordon)
> insertRow( matrix( 1:3, ncol=1 ), 2, 4 )
     [,1]
[1,]    1
[2,]    4
[3,]    2
[4,]    3
> 
> # insert a column to a single-row matrix
> insertCol( matrix( 1:3, nrow=1 ), 2, 4 )
     [,1] [,2] [,3] [,4]
[1,]    1    4    2    3
> 
> proc.time()
   user  system elapsed 
  0.132   0.020   0.137 

Generated by dwww version 1.15 on Wed Jun 26 01:07:35 CEST 2024.