Functions of esProc/R/Python/Perl in Structured Data Process by Comparison :Chapter7. Inserting, Adding and Removing Column


    tbl.derive(col1)         // Add a column col1 to the Table sequence 

esProc is unable to execute some operations such as deleting the column from the existing Table sequence or inserting the column into the existing Table sequence, however, it is very easy to create a new Table sequence. In fact, the action for creating a new table sequence has the same process as that for adding and deleting the existing Table sequence.,col2,col3)             //Only generate sequences for three columns, col1,col2,col3, delete other columns,col5,col2,col3)    //Generate the Table sequence of col5 where a new column is inserted


No concept of the column is defined in the 2D array. When performing column operations, you will end up in trouble since the actions for loop row-by-row and additional delete are required.

The sample code is as follows:





     foreach(@carts){     #Repeat the operation, and insert element 3 in between Column 2 and 3

     $_=[ (@$_[0..1]), 3, (@$_[2..scalar(@$_)-1]) ];                        #Note that here $_ is the array pointer, only when it is prefixed with @ can it indicate the array itself, so that its sub-array is written as @$_[n..m] in order to get a sub-array


     foreach(@carts){     # Repeat the operation for each record, and append element 9 to the end

         push $_,9;        # here $_ is not prefixed with @, which is a little hard to understand


     foreach(@carts){     #Repeat the operation for each record, and delete the third element

         splice ($_, 2, 1);       



Since no concept of the column is defined in the 2D array, the column operation still needs to be repeated row by row, so does the modification operation. However, what is more convenient than Perl comes here that it provides insert and del functions, which allows you to perform Insert and Delete operations on the element of an array in an easy way.





     for i in range(0,len(carts)):       # Insert the column

                carts[i].insert(2, 3) 

     for i in range(0,len(carts)):       # Append the column


     for i in range(0,len(carts)):       # Delete the column

               del carts[i][2]        


    #Add a column to the data frame, which is named score with the column values, 12, 13, 23




    tbl[,-n]                         # Delete Column n of tbl

    tbl$col2=NULL          #Delete that column named col2



About datathinker

a technical consultant on Database performance optimization, Database storage expansion, Off-database computation. personal blog at: datakeywrod, website: raqsoft
This entry was posted in Structured Data Process and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s