% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_val.R
\name{get_val}
\alias{get_val}
\alias{put_val<-}
\title{Get Values from an Array}
\usage{
get_val(A, i = NULL, j = NULL, k = NULL, l = NULL, subs = NULL)

put_val(A, i = NULL, j = NULL, k = NULL, l = NULL, subs = NULL) <- value
}
\arguments{
\item{A}{An array object}

\item{i}{Vector consisting of the subscripts for the 1st dimension}

\item{j}{Vector consisting of the subscripts for the 2nd dimension}

\item{k}{Vector consisting of the subscripts for the 3rd dimension}

\item{l}{Vector consisting of the subscripts for the 4th dimension}

\item{subs}{string specifying the subscripts such as "1:2, , 4, 2:2" \cr
or a numeric vector consisting of the scalar subscript for each dim.}

\item{value}{The value to be assigned.}
}
\value{
\code{get_val(A, i,j.,k,l)} returns
 \code{A[i,j,k,l]}. \cr
 \code{put_val(A, i,j,k,l) <- value} replaces
 \code{A[i,j,k,l]} with \code{value}.
}
\description{
Get Values from an Array
}
\details{
It is assumed that \code{A} is an array. \cr
When \code{A} is a list of data frames, use \code{get_valL} instead.\cr
When numeric \code{subs} is given it must be a vector of length
\code{length(dim(A))} specifying a scalar element of \code{A}. \cr
\cr
\code{get_val(A,i,j,k,l)} returns \code{A[i,j,k,l]}. \cr
\code{put_val(A,i,j,k,l) <- value} puts the value at \code{A[i,j,k,l]}.
\cr
Therefore, when \code{A} is an array, better use \code{A[i,j,k,l]}.
\cr

\code{get_val(A,i,j,k,l)} is equivalent to \code{get_val(A,subs=subs)}
\cr where \code{subs} contains the values of \code{i,j,k,l} as a string.
\cr For example, \cr
\code{get_val(A, 1:2, , 3)} is equivalent to
\code{get_val(A, subs="1:2, , 3")}. \cr
\cr
Use \code{subs=} when the # of dimensions is more than 5.
\cr

\code{subs=} has priority over \code{i,j,k,l}.

\cr
The result will be simplified to a matrix or vector if possible.
}
\examples{
# set up an array B
dims=c(5,4,3,2)
B <- array(0,dims)
B[,,,1] <- demomat(5,4,3)*10+1
B[,,,2] <- demomat(5,4,3)*10+2
dimnames(B) <-
 mapply( function(x,y){paste(x,1:y,sep="")}, letters[1:length(dims)],dims)

# get B[5,4,3,2]
res1=get_val(B,5,4,3,2)
res2=get_val(B,subs=c(5,4,3,2))
res3=get_val(B,subs="5,4,3,2")
Print(res1,res2,res3)

# get B[2,,3,]:  cannot use numeric subs here.
res1=get_val(B,2,,3)
res3=get_val(B,subs="2,,3,")
Print(res1, res3 )

# modify B[,1,2:3,1]
( temp <- B[,1,2:3,1] )
put_val(B,,1,2:3,1) <- -9999
B[,1,2:3,1]
put_val(B,subs=",1,2:3,1") <- temp
B[,1,2:3,1]
put_val(B,subs=c(1,1,1,2)) <- -9999
B[1,1,1,2]


}
