Remove a subset
remove.Rd
Selects the row and the varaibles to remove by specifing a condition using a formula.
Details
The formula is composed of two part:
column_names ~ rows_conditions
the left-hand side are the names of the column to remove, and the right-hand the operation to remove the rows, using the I()
function.
For example:
column_names1 + column_names2 ~ I(column_names1 == "a") + I(column_names2 > 4)
first the row are selected to be removed if the observation in the column_names1
are equal to a
and if the observation in the column_names2
are biggers than 4
, then the column_names1
and column_names2
are removed and the other varaibles are returned.
If na.remove
is set to TRUE
, after the subsetting the observations with missing are removed.
Examples
data("airquality")
dt <- airquality
head(remove(from = dt, formula = .~ I(Ozone > 10)))
#> Ozone Solar.R Wind Temp Month Day
#> NA NA NA NA NA NA NA
#> 9 8 19 20.1 61 5 9
#> NA.1 NA NA NA NA NA NA
#> 11 7 NA 6.9 74 5 11
#> 18 6 78 18.4 57 5 18
#> 21 1 8 9.7 59 5 21
head(remove(from = dt, formula = .~ I(Ozone > 10), na.remove = TRUE))
#> Ozone Solar.R Wind Temp Month Day
#> 9 8 19 20.1 61 5 9
#> 18 6 78 18.4 57 5 18
#> 21 1 8 9.7 59 5 21
#> 23 4 25 9.7 61 5 23
#> 73 10 264 14.3 73 7 12
#> 76 7 48 14.3 80 7 15
head(remove(from = dt, formula = Ozone ~ .))
#> Solar.R Wind Temp Month Day
#> 1 190 7.4 67 5 1
#> 2 118 8.0 72 5 2
#> 3 149 12.6 74 5 3
#> 4 313 11.5 62 5 4
#> 5 NA 14.3 56 5 5
#> 6 NA 14.9 66 5 6
head(remove(from = dt, formula = Ozone~ I(Ozone > 10)))
#> Solar.R Wind Temp Month Day
#> NA NA NA NA NA NA
#> 9 19 20.1 61 5 9
#> NA.1 NA NA NA NA NA
#> 11 NA 6.9 74 5 11
#> 18 78 18.4 57 5 18
#> 21 8 9.7 59 5 21
head(remove(from = dt, formula = Ozone + Wind~ I(Ozone > 10)))
#> Solar.R Temp Month Day
#> NA NA NA NA NA
#> 9 19 61 5 9
#> NA.1 NA NA NA NA
#> 11 NA 74 5 11
#> 18 78 57 5 18
#> 21 8 59 5 21
head(remove(from = dt, formula = Ozone + . ~ I(Ozone > 10)))
#> Ozone Solar.R Wind Temp Month Day
#> NA NA NA NA NA NA NA
#> 9 8 19 20.1 61 5 9
#> NA.1 NA NA NA NA NA NA
#> 11 7 NA 6.9 74 5 11
#> 18 6 78 18.4 57 5 18
#> 21 1 8 9.7 59 5 21
head(remove(from = dt, formula = Ozone + NULL ~ I(Ozone > 10)))
#> Solar.R Wind Temp Month Day
#> NA NA NA NA NA NA
#> 9 19 20.1 61 5 9
#> NA.1 NA NA NA NA NA
#> 11 NA 6.9 74 5 11
#> 18 78 18.4 57 5 18
#> 21 8 9.7 59 5 21