=tbl.delete([1,3,5]) // Delete Records 1, 3 and 5
=tbl.delete(15) // Delete Record 15
=tbl.delete(tbl.pselect@a(col1>50)) //Delete any record where col1>50 is true
splice(@myarray,1,3); #Subsequent three elements from the second position are removed, and then @myarray=(1,5,6,7,8,9,10),
splice(@myarray,5,1); # Delete Element 6
delete @myarray[1,3,5]; #Delete the elements in the positions 2, 4, 6, and subsequent elements are not be moved forward, so that the length of array remains unchanged
Some defects are:
- splice cannot remove more than one discontinuous elements at a time.
- After the element is removed by delete, the subsequent elements cannot be moved forward and the length of array remains unchanged, so that it is not completely removed.
- You cannot remove the element according to specific criterion, only be allowed to find the sequence number of element which matches with specific criterion, and then remove it.
- To find the element which matches with specific criterion will take more works, refer to the Section Find Records.
As what Perl does, Python provides a delete function for an array, which can only be used to remove individual element or a number of continuous elements with removal by specific criterion disabled, failing to remove several discontinuous elements at a time, for example:
del data[3:5] #Delete the elements from Position 3 to Position 4, namely, those elements in the positions of >=3 and <5
del data #Delete the element of Position 2, namely, Element 3
If you want to delete the array element based on specific criterion, only the sequence numbers of records which are matched with specific criterion will be available. Thenthe resulting records will be deleted one-by-one, refer to the Section Find Records
tbl[-n,] #Delete Row n from tbl
newtbl<-tbl [tbl $c1>50,] #As shown in the Section 7, delete the records where c1 is less than and equal to 50