read.multi.lsd {LSDinterface} | R Documentation |
Read all instances of LSD variables (time series) from a LSD results file
Description
This function reads the data series associated to all instances of each selected variable from a LSD results file (.res).
Usage
read.multi.lsd( file, col.names = NULL, nrows = -1, skip = 0,
check.names = TRUE, posit = NULL,
posit.match = c( "fixed", "glob", "regex" ),
posit.cols = FALSE )
Arguments
file |
the name of the LSD results file which the data are to be read from. If it does not contain an absolute path, the file name is relative to the current working directory, |
col.names |
a vector of optional names for the variables. The default is to read all variables. |
nrows |
integer: the maximum number of time steps (rows) to read in. Negative and other invalid values are ignored. The default is to read all rows. |
skip |
integer: the number of time steps (rows) of the results file to skip before beginning to read data. The default is to read from the first time step (t = 1). |
check.names |
logical. If |
posit |
a string, a vector of strings or an integer vector describing the LSD object position of the variable(s) to select. If an integer vector, it should define the position of a SINGLE LSD object. If a string or vector of strings, each element should define one or more different LSD objects, so the returning matrix will contain variables from more than one object. By setting |
posit.match |
a string defining how the |
posit.cols |
logical. If |
Details
Selection restriction arguments can be provided as needed; when not specified, all available cases are selected.
When posit
is supplied together with col.names
, the selection process is done in two steps. Firstly, the column names set by col.names
are selected. Secondly, the instances defined by posit
are selected from the first selection set.
See select.colnames.lsd
and select.colattrs.lsd
for examples on how to apply advanced selection options.
Value
Returns a named list of matrices, each containing one of the selected variables' time series from the results file.
Variable names are converted to valid R ones when defining list names. Matrix column names are not "cleaned", even for single instanced variables. The column names include all the header information contained in the LSD results file.
Note
For extracting data from multiple similar files (like sensitivity analysis results), see read.list.lsd
.
Author(s)
Marcelo C. Pereira
See Also
list.files.lsd()
read.single.lsd()
,
read.list.lsd()
,
read.3d.lsd()
,
read.4d.lsd()
,
read.raw.lsd()
Examples
# get the list of file names of example LSD results
files <- list.files.lsd( system.file( "extdata", package = "LSDinterface" ) )
# load first .res file into a simple matrix (all instances),
macroList <- read.multi.lsd( files[ 1 ] )
length( macroList ) # number of lists holding variables
names( macroList ) # name of each list
print( macroList[[ 1 ]][ 1 : 5, , drop = FALSE ] )
print( macroList$X_A1p[ 10 : 20, ] )
# read first instance of 2 variables, skipping the initial 20 time steps
# and keeping up to 30 time steps (from t = 21 up to t = 30), positions in cols
varsList21_30 <- read.multi.lsd( files[ 2 ], c( "_A1p", "_growth1" ),
skip = 20, nrows = 30, posit.cols = TRUE )
print( varsList21_30[[ 1 ]] )
print( varsList21_30$X_growth1 )