<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic moving a few columns/rows from table a to b in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825873#M100650</link>
    <description>&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Clear Symbols();
// Open a file dialog to choose the text file
txtFilePath = Pick File("Choose a text file", {"Text Files|*.txt"});
 
// Check if a file was selected
If(txtFilePath != "", 
    // Convert the file path to ensure it's in the correct format
	txtFilePath = Convert File Path(txtFilePath);
 
    // Import the text file into a new JMP table
	dt1 = Open(
		txtFilePath,
		Delimiter("\t") // Change delimiter if necessary
	);
 
    // Specify the row to use for column names (e.g., row 1)
	columnNamesRow = 16;
 
    // Specify the columns to extract (e.g., columns 1, 2, 3)
	columnsToExtract = {1, 17, 18, 22}; // Adjust column indices as needed
 
	// Extract the column names from the specified row and columns
   
	columnNamesList = {};
	For(j = 1, j &amp;lt;= N Items(columnsToExtract), j++,
		colIndex = columnsToExtract[j];
		columnNamesList[j] = :Column(colIndex)[columnNamesRow];
	);
    
   
    // Create a new JMP table with the extracted column names
	dt2 = New Table("Converted Table");
 
    
  
	For(i = 1, i &amp;lt;= N Items(columnNamesList), i++,
		dt2 &amp;lt;&amp;lt; New Column(Char(columnNamesList[i]), Character); // Adjust column type as needed
	);
 
    // Specify the rows to extract (e.g., rows 2 to 10)
	startRow = 17;
	endRow = 65;
//
	// Loop through the specified rows and add them to the JMP table
	For(i = startRow, i &amp;lt;= endRow, i++,
		dt2 &amp;lt;&amp;lt; Add Rows(1);
		For(j = 1, j &amp;lt;= N Items(columnsToExtract), j++,
			colIndex = columnsToExtract[j];
           
			dt2:Column(j)[i - startRow + 1] = dt1:Column(colIndex)[i];
		);
	);
 
    // Close the imported table
	Close(dt1);
, 
    // If no file was selected, show a message
	Show Message("No file selected.")
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;I am getting a same error messages:&amp;nbsp;
&lt;P&gt;Scoped data table access requires a data table column or variable at row 1 in access or evaluation of 'dt1:Column' , dt1:Column( colIndex ) /*###*/&lt;/P&gt;
&lt;P&gt;at line 49&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Sun, 05 Jan 2025 06:57:45 GMT</pubDate>
    <dc:creator>RepeatedCoyote3</dc:creator>
    <dc:date>2025-01-05T06:57:45Z</dc:date>
    <item>
      <title>moving a few columns/rows from table a to b</title>
      <link>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825873#M100650</link>
      <description>&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Clear Symbols();
// Open a file dialog to choose the text file
txtFilePath = Pick File("Choose a text file", {"Text Files|*.txt"});
 
// Check if a file was selected
If(txtFilePath != "", 
    // Convert the file path to ensure it's in the correct format
	txtFilePath = Convert File Path(txtFilePath);
 
    // Import the text file into a new JMP table
	dt1 = Open(
		txtFilePath,
		Delimiter("\t") // Change delimiter if necessary
	);
 
    // Specify the row to use for column names (e.g., row 1)
	columnNamesRow = 16;
 
    // Specify the columns to extract (e.g., columns 1, 2, 3)
	columnsToExtract = {1, 17, 18, 22}; // Adjust column indices as needed
 
	// Extract the column names from the specified row and columns
   
	columnNamesList = {};
	For(j = 1, j &amp;lt;= N Items(columnsToExtract), j++,
		colIndex = columnsToExtract[j];
		columnNamesList[j] = :Column(colIndex)[columnNamesRow];
	);
    
   
    // Create a new JMP table with the extracted column names
	dt2 = New Table("Converted Table");
 
    
  
	For(i = 1, i &amp;lt;= N Items(columnNamesList), i++,
		dt2 &amp;lt;&amp;lt; New Column(Char(columnNamesList[i]), Character); // Adjust column type as needed
	);
 
    // Specify the rows to extract (e.g., rows 2 to 10)
	startRow = 17;
	endRow = 65;
//
	// Loop through the specified rows and add them to the JMP table
	For(i = startRow, i &amp;lt;= endRow, i++,
		dt2 &amp;lt;&amp;lt; Add Rows(1);
		For(j = 1, j &amp;lt;= N Items(columnsToExtract), j++,
			colIndex = columnsToExtract[j];
           
			dt2:Column(j)[i - startRow + 1] = dt1:Column(colIndex)[i];
		);
	);
 
    // Close the imported table
	Close(dt1);
, 
    // If no file was selected, show a message
	Show Message("No file selected.")
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;I am getting a same error messages:&amp;nbsp;
&lt;P&gt;Scoped data table access requires a data table column or variable at row 1 in access or evaluation of 'dt1:Column' , dt1:Column( colIndex ) /*###*/&lt;/P&gt;
&lt;P&gt;at line 49&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sun, 05 Jan 2025 06:57:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825873#M100650</guid>
      <dc:creator>RepeatedCoyote3</dc:creator>
      <dc:date>2025-01-05T06:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: moving a few columns/rows from table a to b</title>
      <link>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825887#M100651</link>
      <description>&lt;P&gt;Syntax for referencing to columns is incorrect (you are combining Column() and As Column() (the table:column syntax)). &lt;/P&gt;
&lt;P&gt;Changing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt2:Column(j)[i - startRow + 1] = dt1:Column(colIndex)[i];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column(dt2, j)[i - startRow + 1] = Column(dt1, colIndex)[i];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;might work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, there might be easier methods to do what you want to achieve but it would require for us to see an example file and the wanted result.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jan 2025 07:04:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825887#M100651</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-01-05T07:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: moving a few columns/rows from table a to b</title>
      <link>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825889#M100653</link>
      <description>&lt;P&gt;As Jarmo indicates, for some of the steps, JMP provides pre-defined modules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By using such modules:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;the code gets shorter and easier to understand&lt;/LI&gt;&lt;LI&gt;JMP handles the data types automatically&lt;/LI&gt;&lt;LI&gt;the execution is much faster&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;txtFilePath = "$SAMPLE_IMPORT_DATA/Animals_line3.txt";
columnNamesRow = 3;
columnsToExtract = {"species", "miles"};
startRow = 2;
endRow = 10;

dt1 = Open( txtFilePath, 
	Import Settings( Labels( 0 ) )
);
wait(0); //let JMP relax before it continues with the next steps&lt;BR /&gt;
if(columnNamesRow&amp;gt;1, dt1 &amp;lt;&amp;lt; delete rows( 1 :: (columnNamesRow - 1) ));&lt;BR /&gt;dt1 &amp;lt;&amp;lt; move up; 

dt2 = dt1 &amp;lt;&amp;lt; Subset(
	Rows( startRow :: endRow ),
	columns( columnsToExtract )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jan 2025 08:39:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/moving-a-few-columns-rows-from-table-a-to-b/m-p/825889#M100653</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-01-05T08:39:27Z</dc:date>
    </item>
  </channel>
</rss>

