Message Boards Message Boards

0
|
5311 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Append a string to an array (list?) of numbers?

Posted 7 years ago

Edit : Resolved: See below.

I have an array generated from the following:

array1=Range[10]
array1={1,2,3,4,5,6,7,8,9,10}

As expected. However, A bit later in my notebook I need to make a table out of this array, but I need the first element to be empty. I have tried the following:

Tableform[Transpose[{{Append[{" "},array1]},{array2}}]]

The issue seems to be that Append creates a 2d array instead of simply adding an element to array1. I would think that some data type conversion (integer to string) or something would be necessary, but this does not seem to be something that I can see.

Sorry for being new. Thanks!

POSTED BY: Sarah Chastain
4 Replies
Posted 7 years ago

Append takes the list (or expression) as its first argument, and the thing to append as the second.

So when you showed Append[{" "},array1], I wonder if you meant Append[array1, " "].

Also, what format of table were you hoping to get? That wasn't clear from your original post, especially since you're starting from a 1-dimension list. I just wondered if you meant a a 2-row table where the first row is blank, and the second row is the contents of array1, or if you wanted to split up array1 into into 2 rows with 5 columns, or just what you wanted.

One way to ask this is to hard-code the final output that I wanted, and then ask what code could take me from the input to that output.

POSTED BY: Joel Klein
Posted 7 years ago

It looks like I misunderstood the Append command. I should have been using Insert like the above.

POSTED BY: Sarah Chastain
Posted 7 years ago

Sarah,

Is this what you are trying to achieve?

array1 = Insert[array1, "", 1]

{, 1, 2, 3, 4, 5, 6, 7, 8, 
POSTED BY: Paul Cleary
Posted 7 years ago

Paul, This is exactly what I needed. I'll have to remember the Insert function. Thanks!

POSTED BY: Sarah Chastain
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract