Description Usage Arguments Author(s) Examples
Save/read a fortran-formatted binary file that was saved at a defined precision (single or double).
1 2 3 4 5 |
X |
Numeric matrix to save |
filename |
Name of the binary file to save/read |
row.names |
|
col.names |
|
size |
Size of a real variable in bytes ( |
indexRow |
Vector of integers indicating the rows to be read from the file. Default |
indexCol |
Vector of integers indicating the columns to be read from the file. Default |
verbose |
|
Marco Lopez-Cruz (lopezcru@msu.edu) and Gustavo de los Campos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | require(SFSI)
data(wheatHTP)
# Save matrix
saveBinary(X,paste0(tempdir(),"/Matrix1.bin"),size=4) # as single-precision
saveBinary(X,paste0(tempdir(),"/Matrix2.bin"),size=8) # as double-precision
# Read the single-precision matrix
X2 = readBinary(paste0(tempdir(),"/Matrix1.bin"))
X2[1:10,1:5]
sum(abs(X-X2)) # Note the loss of precision
# Read the double-precision matrix
X2 = readBinary(paste0(tempdir(),"/Matrix2.bin"))
X2[1:10,1:5]
sum(abs(X-X2)) # No loss of precision
# Read specific rows and columns
indexRow = c(2,4,5,8,10)
indexCol = c(1,2,6,7,10)
X2 = readBinary(paste0(tempdir(),"/Matrix2.bin"),indexRow=indexRow,indexCol=indexCol)
X2
sum(abs(X[indexRow,indexCol]-X2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.