RE: Adding columns and rows to a table
- To: mathgroup at smc.vnet.net
- Subject: [mg33493] RE: [mg33439] Adding columns and rows to a table
- From: "Harvey P. Dale" <hpd1 at nyu.edu>
- Date: Fri, 22 Mar 2002 04:08:59 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Philip: This may help: cols[l_List]:=Module[{tab2=Flatten/@({#,{#[[-1]]}, {#[[-1]]}}&/@l)},Join[tab2,{Last[tab2]},{Last[tab2]}]] Best, Harvey Harvey P. Dale University Professor of Philanthropy and the Law Director, National Center on Philanthropy and the Law New York University School of Law Room 206A 110 West 3rd Street New York, N.Y. 10012-1074 -----Original Message----- From: Philip M. Howe [mailto:pmhowe at lanl.gov] To: mathgroup at smc.vnet.net Subject: [mg33493] [mg33439] Adding columns and rows to a table Hello, I want to add to a table two columns that match the last column, and two rows that match the last row. Thus, if my table is {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; I want to modify it such that I end up with {{1,2,3,4,4,4}, {5,6,7,8,8,8}, {9,10,11,12,12,12}, { 9,10,11,12,12,12}, {9,10,11,12,12,12}}; This works: tab1 = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; tab1c = Transpose[ Append[Append[Transpose[tab1], Transpose[tab1][[-1]]], Transpose[tab1][[-1]]]]; tab1d = Append[Append[tab1c, tab1c[[-1]]], tab1c[[-1]]] // TableForm However, I bet there are much more efficient and elegant ways of doing this. Any suggestions? Thanks in advance for the help. The ideas I obtain from you folks are extremely helpful. Regards, Phil -- Philip M. Howe Program Manager, Stockpile Surety Los Alamos National Laboratory (505) 665-5332 (505) 667-9498 Fax: 505-665-5249 email pmhowe at lanl.gov Mail Stop P945 ________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information on a proactive anti-virus service working around the clock, around the globe, visit http://www.messagelabs.com ________________________________________________________________________