Subsetting operators
%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 %not% y <- value x %just% y x %just% y <- value ## Default S3 method: x %not% y ## Default S3 method: x %not% y <- value ## S3 method for class 'data.frame' x %not% y ## S3 method for class 'data.frame' x %not% y <- value ## S3 method for class 'matrix' x %not% y ## S3 method for class 'matrix' x %not% y <- value ## S3 method for class 'list' x %not% y ## S3 method for class 'list' x %not% y <- value ## Default S3 method: x %just% y ## Default S3 method: x %just% y <- value ## S3 method for class 'data.frame' x %just% y ## S3 method for class 'data.frame' x %just% y <- value ## S3 method for class 'matrix' x %just% y ## S3 method for class 'matrix' x %just% y <- value ## S3 method for class 'list' x %just% y ## S3 method for class 'list' x %just% y <- value
x |
Object to subset |
y |
List of items to include if they are/aren't in |
value |
The object(s) to assign to the subsetted |
The behavior of %not% and %just% are different when you're subsetting
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.
All of x that are in y (%just%) or all of x that are not in
y (%not%).
x <- 1:5
y <- 3:8
x %just% y # 3 4 5
x %not% y # 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
mtcars %not% 1:5 # drops columns 1 through 5
# Assignment works for data frames as well
mtcars %just% c("mpg", "qsec") <- gscale(mtcars, c("mpg", "qsec"))
mtcars %not% c("mpg", "qsec") <- gscale(mtcars %not% c("mpg", "qsec"))Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.