Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 127

Warning – Redefine existing operators

Оглавление

It is even possible to redefine elementary operators such as + with the aforementioned code. This is of course not a wise thing to do, but we understand how it can be a fun practical joke or a tricky job interview question.

The following are some common operators that help working with data.

operator – other

# create a list x <- c(10:20) x ## [1] 10 11 12 13 14 15 16 17 18 19 20 # %in% can find an element in a vector 2 %in% x # FALSE since 2 is not an element of x ## [1] FALSE 11 %in% x # TRUE since 11 is in x ## [1] TRUE x[x %in% c(12,13)] # selects elements from x ## [1] 12 13 x[2:4] # selects the elements with index ## [1] 11 12 13 # between 2 and 4

The Big R-Book

Подняться наверх