data_pop {quickcode} | R Documentation |
Remove last n rows or column or specified elements from a data frame like array_pop in PHP
Description
Shorthand to remove elements from a data frame and save as the same name
Usage
data_pop(., n = 1, which = c("rows", "cols"), ret = FALSE)
Arguments
. |
parent data |
n |
number of elements to remove |
which |
whether to remove from row or from column |
ret |
TRUE or FALSE. whether to return value instead of setting it to the parent data |
Value
data with elements removed
Examples
data.01 <- mtcars[1:7,]
#task: remove 1 element from the end of the data and set it to the data name
data.01 #data.01 data before pop
data_pop(data.01) #does not return anything
data.01 #data.01 data updated after pop
#task: remove 3 columns from the end of the data and set it to the data name
data.01 #data.01 data before pop
data_pop(data.01, n = 3, which = "cols") #does not return anything, but updates data
data.01 #data.01 data updated after pop
#task: remove 5 elements from the end, but do not set it to the data name
data.01 #data.01 data before pop
data_pop(data.01,5, ret = TRUE) #return modified data
data.01 #data.01 data remains the same after pop
[Package quickcode version 0.9.1 Index]