How do I combine column vectors with different rows

For example I have two column vectors (string)

A = { "aa", "ab", "ac" }

B = { "bb", "bc" }

I want to create:

AB =  aa   .
      ab  bb
      ac  bc

or

AB =  aa  bb
      ab  bc
      ac    .

1 Answer



0



If your data are string arrays, then you could concatenate a "." onto the top (or bottom) of the string array with fewer rows, like this:

string A = { "aa", "ab", "ac" };
string B = { "bb", "bc" };

B2 = "."$|B;
AB = A$~B2;
"AB = " AB;

In the code above, $| performs vertical concatenation of strings and string arrays while $~ performs horizontal concatenation of strings and string arrays.

If what you have is instead character matrices, then you have the option of adding a GAUSS missing value as the extra element or a character dot:

 
AM = { "aa", "ab", "ac" };
BM = { "bb", "bc" };

BM2 = miss(0,0)|B;
ABM = A~B2;
"AB = " AB;

The miss function creates a missing value. If you wanted instead to add a character dot, then change the assignment of BM2 to:

BM2 = "."|B;

aptech

1,773

Your Answer

1 Answer

0

If your data are string arrays, then you could concatenate a "." onto the top (or bottom) of the string array with fewer rows, like this:

string A = { "aa", "ab", "ac" };
string B = { "bb", "bc" };

B2 = "."$|B;
AB = A$~B2;
"AB = " AB;

In the code above, $| performs vertical concatenation of strings and string arrays while $~ performs horizontal concatenation of strings and string arrays.

If what you have is instead character matrices, then you have the option of adding a GAUSS missing value as the extra element or a character dot:

 
AM = { "aa", "ab", "ac" };
BM = { "bb", "bc" };

BM2 = miss(0,0)|B;
ABM = A~B2;
"AB = " AB;

The miss function creates a missing value. If you wanted instead to add a character dot, then change the assignment of BM2 to:

BM2 = "."|B;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.