Skip to contents

Converts a numeric value to character. This is essentially a wrapper over base::as.character().

Usage

num2str(A, format)

# S4 method for numeric,missing
num2str(A)

# S4 method for array,missing
num2str(A)

# S4 method for numeric,numeric
num2str(A, format)

# S4 method for array,numeric
num2str(A, format)

# S4 method for numeric,character
num2str(A, format)

# S4 method for array,character
num2str(A, format)

Arguments

A

numeric object

format

either a number or a string (see fmt argument of base::sprintf()).

Value

A, with its format possibly reshaped by format

Methods (by class)

  • num2str(A = numeric, format = missing): Converting a vector to character

  • num2str(A = array, format = missing): Converting an array to character

  • num2str(A = numeric, format = numeric): Rounding a vector, then converting to character

  • num2str(A = array, format = numeric): Rounding an arrray, then converting to character

  • num2str(A = numeric, format = character): Formatting a vector, then converting to character

  • num2str(A = array, format = character): Formatting an array, then converting to character

Author

Waldir Leoncio

Examples

X <- rnorm(10)
num2str(X)
#>  [1] "-0.606734505124855"  "0.0423361886966367"  "0.644511913946207"  
#>  [4] "0.122525081682147"   "-0.309502818542158"  "1.32156305905714"   
#>  [7] "-0.0111281275179637" "-0.601015380744239"  "0.195850171589368"  
#> [10] "-0.653282887776738" 
num2str(X, 2)
#>  [1] "-0.61" "0.04"  "0.64"  "0.12"  "-0.31" "1.32"  "-0.01" "-0.6"  "0.2"  
#> [10] "-0.65"
A <- matrix(runif(4), 2)
num2str(A)
#>      [,1]                [,2]                
#> [1,] "0.758094281423837" "0.496149426326156" 
#> [2,] "0.22195178642869"  "0.0822154453489929"
num2str(A, 3)
#>      [,1]    [,2]   
#> [1,] "0.758" "0.496"
#> [2,] "0.222" "0.082"
num2str(pi * 10, "%e")
#> [1] "3.141593e+01"