tbl.insert(5,value1:col1,value2:col2,……) //Insert a record preceding Row 5
In Perl, to insert an element into an array, it may be easy if this is at the beginning, where shift and unshift functions are available, for example:
@array = (“one”,”two”,”three”);
$m = shift (@array); #$m Get “one”, now @array is (“two”, “three”)
shift @array; #@array is (“three”)now
shift @array; #@array is null now
unshift(@array,5); #@array is(5) now
unshift @array,4; #@array is(4,5) now
To insert an element in the middle of an array, you will get into big trouble since no existing function is available. There are two alternative methods, take an example as below:
Insert element 3 in position 3 of @array to make the array change to @array=(1,2,3,4,5)
1.Generate a new array
@array = ( (@array[0..1]), 3, (@array[2..@array]) );
2.Write a loop to shift the positions of the elements in turn
It is much simpler to insert a record in Python than in Perl. Python provides an insert function and is as easy as esProc.
a.insert(2,[4,”Liu Liu”,7000,43]) #Insert the record [4,”Liu Liu”,7000,43] preceding Position 2 .
It seems that in R, the two data frames can be merged only, while the insertion operation is disabled. Of course, a matrix list will be another matter if this is the case. Since a 2D table is achieved mainly by utilizing data frames, here is only to discuss the data frame.
Here, by merging the data frames, the record can be inserted indirectly, for example:
dd2 <- rbind(dd[1,], dd1,dd[2:3,]) #Indicate to insert dd1 in the middle of Row 1 and 2 of dd