get_valL {lazy.tools} R Documentation

## Get Values from a List Consisting of Data Frames

### Description

Get Values from a List Consisting of Data Frames

### Usage

```get_valL(L, s1 = NULL, s2 = NULL, s3 = NULL, simplify = 1)

put_valL(L, s1 = NULL, s2 = NULL, s3 = NULL) <- value
```

### Arguments

 `L` A list of data frames `s1` Vector consisting of the subscripts for the 1st dimension `s2` Vector consisting of the subscripts for the 2nd dimension `s3` Vector consisting of the subscripts for the 3rd dimension `simplify` = 0 to leave the result of get_valL unsimplified (list) `value` The value to be assigned. Either a vector or a matrix.

### Details

It is assumed that `L` is a list consisting of several data frames. and the third subscript, `s3` is for the list.
Therefore, `get_valL(L,,,s3)` with scalar s3 is equivalent to `L[[s3]]`
and `get_valL(L,,,2:3)` returns the 2nd and the 3rd data frames in a list.

`s1,s2,s3` can be a set of vectors consisting of row/col/list names.

When some of the subscripts are out of range, only the valid ones will be used.

The result will be simplified to a matrix or vector if possible.
When `length(s1)==1`, the result will be a `length(L)` x `ncol(L[[1]])` matrix.
When `length(s2)==1`, the result will be a `ncol(L[[1]])` x `length(L)` matrix.

### Value

`get_valL(L, s1,s2,s3)` returns `(s1,s2)` element(s) of the s3-th data frame(s).
`put_valL(L, s1,s2,s3) <- value` replaces the `s1,s2` element(s) of the data frame(s) specified by `s3` with `value`.

### Examples

```L0 <- list( A=data.frame(demomat(3,2)*10+1)
, B=data.frame(demomat(4,3)*10+2)
, C=data.frame(demomat(5,4)*10+3)
)
L <- L0
get_valL( L, ,,2 ) # should be equal to get_valL( L, ,,"B" )
get_valL( L, 2, )  # should be equal to get_valL( L, "r2",, )
get_valL( L, ,2 )  # should be equal to get_valL( L, , "c2", )
get_valL( L, c(1,3),,3:2 )
get_valL( L, c(1,3),, c("B","A") )

L <- L0; put_valL(L, 1:2,1:2,3) <- 0;                  Print(L)
L <- L0; put_valL(L, 1:2,1:2,c("C","A")) <- 0;         Print(L)
L <- L0; put_valL(L, 3:5,2:4,) <- 0;                   Print(L)
L <- L0; put_valL(L, 3:5,2:4,2) <- 0;                  Print(L)
L <- L0; put_valL(L, 1:4,1,2:3) <- 1:4;                Print(L)
L <- L0; put_valL(L, 1:2,2:3,2:3) <- demomat(2,2)*100; Print(L)

# effect of simplify
L0 <- list( A=data.frame(demomat(3,4)*10+1)
, B=data.frame(demomat(3,4)*10+2)
, C=data.frame(demomat(3,4)*10+3)
)
L <- L0
get_valL( L, ,,2 )
get_valL( L, ,,2, simplify=0 )
get_valL( L, 2, )
get_valL( L, 2,, simplify=0 )
get_valL( L, ,2 )
get_valL( L, ,2, simplify=0 )

# When the selected elements are scalars, the result is a column vector.
get_valL(L0,1:2,1) # matrix
get_valL(L0,1,1)   # col vector
get_valL(L0,1,1:2) # matrix

# mixed type variables in a data frame
A <- data.frame(demomat(3,4)*10+1)
A[,2] <- paste("c",as.character(A[,2]),sep="")
B <- data.frame(demomat(3,4)*10+2)
B[,2] <- paste("c",as.character(B[,2]),sep="")
C <- data.frame(demomat(3,4)*10+3)
C[,2] <- paste("c",as.character(C[,2]),sep="")
L <- list(A=A,B=B,C=C)

get_valL( L, 2, )
get_valL( L, , 2 )

```

[Package lazy.tools version 0.1.3 Index]