Set fall to FALSE for vector operators in R

As indicated in the R documentation , the operator '[' is defined as follows:

x[i, j, ... , drop = TRUE] 

Is there a way to override it to set the default drop value for the FALSE parameter?

+5
source share
1 answer
 `[` <- function(...) base::`[`(...,drop=FALSE) 

This should prevent some unwanted behavior in R, where a matrix that reduces to one row or one column will suddenly behave like c(number,number,number) instead of matrix(c(number,number,number),ncol=1)

+2
source

Source: https://habr.com/ru/post/1206164/


All Articles