char2vma: transforms a character into a vector (or matrix, or array)

Description Usage Arguments Details Value Examples

View source: R/f1.rbsb2.code.r

Description

from a character vector, returns a vector, or a matrix, or an array of characters with possibly names, or dimames. The information can be supplied in different ways for each of the three possibilities. It is advised to try the proposed examples.

Usage

1
char2vma(cha, what=rbsb.vma["v"], xsep=rbsb.sep1, nat="C")

Arguments

cha

The character to transform.

what

Indicates which structure to return: either a vector, a matrix or an array.

For vectors, the possibilities are c/C/u/v/U/V :
rbsb.vma["c"] for a no named character(1); collapsing is done with rbsb.sep0.
rbsb.vma["C"] for a no named character() of any length (components are separated with xsep whiwh are removed from the result); collapsing is done with rbsb.sep0.
rbsb.vma["v"] or rbsb.vma["u"] for a no named vector;
rbsb.vma["V"] for a named vector with all names before the values; then an even number of components must be provided.
rbsb.vma["U"] for a named vector with names interlaced with the value (name\_i, value\_i); then an even number of components must be provided.

For matrices, the possibilities are m/n/o/p/M/N/O/P:
rbsb.vma["m"] for a no named matrix given by row, two adjacent rows being separated with xsep sequence, introduced as one of the component of cha, then for a 2x3 matrix, the length of cha will be 6+2 = 8.
rbsb.vma["n"] for a matrix with only the columns names. The expected sequence is the names of columns, then the values as for rbsb.vma["m"]; then for a 2x3 matrix, the length of cha will be 3+1+8=12.
rbsb.vma["o"] for a matrix with only rows named. The expected sequence is name of row, values of rows... Then 2x3 will imply a length of 8+2=10.
rbsb.vma["p"] when names for columns and rows, in a mixed way... Then 2x3 will imply a length of 14.
When rbsb.vma["M"],rbsb.vma["N"],rbsb.vma["O"],rbsb.vma["P"], the same but the matrix will be transposed after being read; said in another way, the values are given by columns.

For arrays, the possibilities are a/A/b/B:
rbsb.vma["a"] for a no named array, the dimensions, xsep, the values in the classical order (varying the first index the fastest). 2x3 will give a length of 2+1+6=9.
rbsb.vma["A"] for a dimnamed array, the dimensions, xsep, the dimnames of each dimension in the right order also separated and finished with xsep. 2x3 will gives a length of 2+1+2+1+3+1+6=16.
rbsb.vma["b"] for a named dimensions array, the dimensions, xsep, the names for the dimension in the right order not separated and finished with xsep. 2x3 will gives a length of 2+1+2+1+6=12.
rbsb.vma["B"] for a named and dimnamed array, the dimensions, xsep, the names for the dimension in the right order not separated and finished with xsep, then the dimnames separated before the values. 2x3 will gives a length of (2+1)+(2+1)+(2+1+3+1)+(6)=19.

xsep

Character sequence used to separate the character vector into blocks giving information about the structure (see the examples).

nat

Nature of the returned structure. Can be C for character, N for numeric or L for logical.

Details

The processing is done in character mode but the result can be transformed into numerical or logical values with the help of argument nat.
In fact rbsb.vma coding is used for the argument what. This allows to easily modify the coding.

Value

a vector or a matrix or an array according to the inputs

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 rbsb3k("reset"); # For R checking convenience
 char2vma(letters, "c");
 char2vma(letters, "C", xsep="e");
 char2vma(letters);
 char2vma(letters, "V");
 char2vma(letters, "u");
 char2vma(c(LETTERS, letters), rbsb.vma["V"]);
 char2vma(c("A", "a", "B", "b", "C", "c"), rbsb.vma["U"]);
 char2vma(c(1:3, "//", 4:6), rbsb.vma["m"]);
 char2vma(c(1:3, "//", 4:6), rbsb.vma["M"]);
 char2vma(c(LETTERS[1:3], "//", 1:3, "//", 4:6), rbsb.vma["n"]);
 char2vma(c(LETTERS[1:3], "//", 1:3, "//", 4:6), "N");
 char2vma(c("a", 1:3, "//", "b", 4:6), "o");
 char2vma(c(c(LETTERS[1:3], "//", "a", 1:3, "//", "b", 4:6)), rbsb.vma["p"]);
 char2vma(c(2:4, "//", 1:24), "a");
 char2vma(c(2:4, "//", "one", "two", "//", LETTERS[1:3], "//", 
 letters[1:4], "//", 1:24), "A");
 char2vma(c(2:4, "//", "one", "two", "//", LETTERS[1:3], "//", 
 letters[1:4], "//", 1:24), "A", nat="N");

rbsb documentation built on May 31, 2017, 1:45 a.m.