%just% and %not% are subsetting convenience functions for situations when you would do x[x %in% y] or x[x %nin% y]. See details for behavior when x is a data frame or matrix.

x %not% y

x 

x %just% y

x 

# S3 method for default
%not%(x, y)

# S3 method for default
%not%(x, y) <- value

# S3 method for data.frame
%not%(x, y)

# S3 method for data.frame
%not%(x, y) <- value

# S3 method for matrix
%not%(x, y)

# S3 method for matrix
%not%(x, y) <- value

# S3 method for default
%just%(x, y)

# S3 method for default
%just%(x, y) <- value

# S3 method for data.frame
%just%(x, y)

# S3 method for data.frame
%just%(x, y) <- value

# S3 method for matrix
%just%(x, y)

# S3 method for matrix
%just%(x, y) <- value

Arguments

x

Object to subset

y

List of items to include if they are/aren't in x

value

The object(s) to assign to the subsetted x

Value

All of x that are in y (%just%) or all of x that are not in y (%not%).

Details

The behavior of data frames or matrices. The subset y in this case is interpreted as column names or indices.

You can also make assignments to the subset in the same way you could if subsetting with brackets.

Examples

x <- 1:5 y <- 3:8 x %just% y # 3 4 5
#> [1] 3 4 5
x %not% y # 1 2
#> [1] 1 2
# Assignment works too x %just% y <- NA # 1 2 NA NA NA x %not% y <- NA # NA NA 3 4 5 mtcars %just% c("mpg", "qsec", "cyl") # keeps only columns with those names
#> mpg qsec cyl #> Mazda RX4 21.0 16.46 6 #> Mazda RX4 Wag 21.0 17.02 6 #> Datsun 710 22.8 18.61 4 #> Hornet 4 Drive 21.4 19.44 6 #> Hornet Sportabout 18.7 17.02 8 #> Valiant 18.1 20.22 6 #> Duster 360 14.3 15.84 8 #> Merc 240D 24.4 20.00 4 #> Merc 230 22.8 22.90 4 #> Merc 280 19.2 18.30 6 #> Merc 280C 17.8 18.90 6 #> Merc 450SE 16.4 17.40 8 #> Merc 450SL 17.3 17.60 8 #> Merc 450SLC 15.2 18.00 8 #> Cadillac Fleetwood 10.4 17.98 8 #> Lincoln Continental 10.4 17.82 8 #> Chrysler Imperial 14.7 17.42 8 #> Fiat 128 32.4 19.47 4 #> Honda Civic 30.4 18.52 4 #> Toyota Corolla 33.9 19.90 4 #> Toyota Corona 21.5 20.01 4 #> Dodge Challenger 15.5 16.87 8 #> AMC Javelin 15.2 17.30 8 #> Camaro Z28 13.3 15.41 8 #> Pontiac Firebird 19.2 17.05 8 #> Fiat X1-9 27.3 18.90 4 #> Porsche 914-2 26.0 16.70 4 #> Lotus Europa 30.4 16.90 4 #> Ford Pantera L 15.8 14.50 8 #> Ferrari Dino 19.7 15.50 6 #> Maserati Bora 15.0 14.60 8 #> Volvo 142E 21.4 18.60 4
mtcars %not% 1:5 # drops columns 1 through 5
#> wt qsec vs am gear carb #> Mazda RX4 2.620 16.46 0 1 4 4 #> Mazda RX4 Wag 2.875 17.02 0 1 4 4 #> Datsun 710 2.320 18.61 1 1 4 1 #> Hornet 4 Drive 3.215 19.44 1 0 3 1 #> Hornet Sportabout 3.440 17.02 0 0 3 2 #> Valiant 3.460 20.22 1 0 3 1 #> Duster 360 3.570 15.84 0 0 3 4 #> Merc 240D 3.190 20.00 1 0 4 2 #> Merc 230 3.150 22.90 1 0 4 2 #> Merc 280 3.440 18.30 1 0 4 4 #> Merc 280C 3.440 18.90 1 0 4 4 #> Merc 450SE 4.070 17.40 0 0 3 3 #> Merc 450SL 3.730 17.60 0 0 3 3 #> Merc 450SLC 3.780 18.00 0 0 3 3 #> Cadillac Fleetwood 5.250 17.98 0 0 3 4 #> Lincoln Continental 5.424 17.82 0 0 3 4 #> Chrysler Imperial 5.345 17.42 0 0 3 4 #> Fiat 128 2.200 19.47 1 1 4 1 #> Honda Civic 1.615 18.52 1 1 4 2 #> Toyota Corolla 1.835 19.90 1 1 4 1 #> Toyota Corona 2.465 20.01 1 0 3 1 #> Dodge Challenger 3.520 16.87 0 0 3 2 #> AMC Javelin 3.435 17.30 0 0 3 2 #> Camaro Z28 3.840 15.41 0 0 3 4 #> Pontiac Firebird 3.845 17.05 0 0 3 2 #> Fiat X1-9 1.935 18.90 1 1 4 1 #> Porsche 914-2 2.140 16.70 0 1 5 2 #> Lotus Europa 1.513 16.90 1 1 5 2 #> Ford Pantera L 3.170 14.50 0 1 5 4 #> Ferrari Dino 2.770 15.50 0 1 5 6 #> Maserati Bora 3.570 14.60 0 1 5 8 #> Volvo 142E 2.780 18.60 1 1 4 2
# Assignment works for data frames as well mtcars %just% c("mpg", "qsec") <- gscale(mtcars, c("mpg", "qsec"))
#> Warning: provided 11 variables to replace 2 variables
mtcars %not% c("mpg", "qsec") <- gscale(mtcars %not% c("mpg", "qsec"))