FNLStat : Utilities : MVNAN
MVNAN
Moves any rows of a matrix with the IMSL missing value code NaN (not a number) in the specified columns to the last rows of the matrix.
Required Arguments
IIND — Index vector option. (Input)
IIND
Meaning
< 0
The first –IIND columns of X are checked for NaN.
> 0
The IIND columns of X given by IND are checked for NaN.
IND — Index vector of length IIND containing the column numbers of X that are to be checked for NaN. (Input if IIND is positive)
If IIND is negative, IND is not referenced and can be a vector of length one.
XNROW by NCOL matrix whose rows are checked for NaN (not a number). (Input/Output)
On output, the rows of X containing NaN are the last NRMISS rows of X.
ISWP — Vector of length NROW specifying the rows that were exchanged (swapped). (Output)
The number of nonzero elements in ISWP is the number of swaps that took place. ISWP(I) = J (J greater than zero) means that rows I and J of X were swapped, i.e., row I of the input X is row J of the output X and row J of the input X is row I of the output X.
Optional Arguments
NROW — Number of rows. (Input)
Default: NROW = size (X,1).
NCOL — Number of columns. (Input)
Default: NCOL = size (X,2).
LDX — Leading dimension of X exactly as specified in the dimension statement of the calling program. (Input)
Default: LDX = size (X,1).
NRMISS — Number of rows that contained NaN in the specified columns of X. (Output)
FORTRAN 90 Interface
Generic: CALL MVNAN (IIND, IND, X, ISWP [])
Specific: The specific interface names are S_MVNAN and D_MVNAN.
FORTRAN 77 Interface
Single: CALL MVNAN (NROW, NCOL, IIND, IND, X, LDX, ISWP, NRMISS)
Double: The double precision name is DMVNAN.
Examples
Example 1
In this example, MVNAN is used to move rows containing NaN in columns 1 and 2 of a 5 by 3 matrix X to the last rows.
 
USE IMSL_LIBRARIES
 
IMPLICIT NONE
INTEGER LDX, NCOL, NROW, J
PARAMETER (NCOL=3, NROW=5, LDX=NROW)
!
INTEGER IIND, IND(1), ISWP(NROW), NOUT, NRMISS
REAL X(LDX,NCOL)
!
DATA (X(1,J),J=1,NCOL)/1.0, 10.0, 100.0/
DATA (X(2,J),J=1,NCOL)/2.0, 20.0, 200.0/
DATA (X(3,J),J=1,NCOL)/3.0, 30.0, 300.0/
DATA (X(4,J),J=1,NCOL)/4.0, 40.0, 400.0/
DATA (X(5,J),J=1,NCOL)/5.0, 50.0, 500.0/
!
X(2,2) = AMACH(6)
X(4,1) = AMACH(6)
IIND = -2
CALL WRRRN ('Input X', X)
CALL MVNAN (IIND, IND, X, ISWP, NRMISS=NRMISS)
CALL WRRRN ('Output X', X)
CALL WRIRN ('ISWP', ISWP)
CALL UMACH (2, NOUT)
WRITE (NOUT,*) ' '
WRITE (NOUT,*) 'NRMISS = ', NRMISS
END
Output
 
Input X
1 2 3
1 1.0 10.0 100.0
2 2.0 NaN 200.0
3 3.0 30.0 300.0
4 NaN 40.0 400.0
5 5.0 50.0 500.0
 
Output X
1 2 3
1 1.0 10.0 100.0
2 5.0 50.0 500.0
3 3.0 30.0 300.0
4 NaN 40.0 400.0
5 2.0 NaN 200.0
 
ISWAP
1 0
2 5
3 0
4 0
5 0
NRMISS = 2
Example 2
In this example, MVNAN is used to move rows containing NaN in column 1 and 3 of a 5 by 3 matrix X to the last rows.
 
USE IMSL_LIBRARIES
 
IMPLICIT NONE
INTEGER LDX, NCOL, NROW, J
PARAMETER (NCOL=3, NROW=5, LDX=NROW)
!
INTEGER IIND, IND(2), ISWP(NROW), NOUT, NRMISS
REAL X(LDX,NCOL)
!
DATA (X(1,J),J=1,NCOL)/1.0, 10.0, 100.0/
DATA (X(2,J),J=1,NCOL)/2.0, 20.0, 200.0/
DATA (X(3,J),J=1,NCOL)/3.0, 30.0, 300.0/
DATA (X(4,J),J=1,NCOL)/4.0, 40.0, 400.0/
DATA (X(5,J),J=1,NCOL)/5.0, 50.0, 500.0/
DATA IND/1, 3/
!
X(2,2) = AMACH(6)
X(4,1) = AMACH(6)
IIND = 2
CALL WRRRN ('Input X', X)
CALL MVNAN (IIND, IND, X, ISWP, NRMISS=NRMISS)
CALL WRRRN ('Output X', X)
CALL WRIRN ('ISWP', ISWP)
CALL UMACH (2, NOUT)
WRITE (NOUT,*) ' '
WRITE (NOUT,*) 'NRMISS = ', NRMISS
END
Output
 
Input X
1 2 3
1 1.0 10.0 100.0
2 2.0 NaN 200.0
3 3.0 30.0 300.0
4 NaN 40.0 400.0
5 5.0 50.0 500.0
 
Output X
1 2 3
1 1.0 10.0 100.0
2 2.0 NaN 200.0
3 3.0 30.0 300.0
4 5.0 50.0 500.0
5 NaN 40.0 400.0
 
 
 
 
 
ISWP
1 0
2 0
3 0
4 5
5 0
NRMISS = 1