Choose Language Hide Translation Bar
Highlighted

## Integer data type vs Number data type

I have a column matrix, called "a", with x rows. I'm trying to create a matrix filled with 1's that has the same number x rows.

When I say newmat = [](N Rows(a), 2), I get the error "Expected integer for number of rows" when trying to create the matrix.

Type(3), and any other integer argument, will return "Integer" but Type(N Rows(a)) returns "Number". I tried setting the x rows to a variable name and trying that, but I get the same error. Is there another way to do this? I haven't found a way to convert a Number type to an Integer type on the boards or in the documentation.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Integer data type vs Number data type

@pen51

``````a = Random Index(100,10);

NewMat = J(N Rows(a),1,1);  // Use the J() to do this ``````

The above sample worked for me Best
Uday
3 REPLIES 3

## Re: Integer data type vs Number data type

@pen51

``````a = Random Index(100,10);

NewMat = J(N Rows(a),1,1);  // Use the J() to do this ``````

The above sample worked for me Best
Uday

## Re: Integer data type vs Number data type

Here are a couple of ways to create the matrix you are looking for

``````clear symbols();
a=[1 ,2 ,3];

b=j(n rows(a),1,1)

// or
b=a;
b[1::n rows(a)]=1;``````
Jim

## Re: Integer data type vs Number data type

Hi @pen51,

@uday_guntupalli is correct that J() is exactly the right function for this.  To get at the reason JMP is yelling at you is that certain JMP functions don't like to take variable names are arguments.  If needed, you can solve these kinds of problems with an eval-parse-eval insert sequence like so:

``eval(parse(eval insert("newmat = [](^N Rows(a)^, 2)")));``

Please use Uday's solution, but this tip may help you later when you encounter a similar situation.

-- Cameron Willden