Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permanently set drop to FALSE for vector operators in R

Tags:

r

matrix

As stated in R documentation, the operator '[' is defined in this way:

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

Is there a way to redefine it in order to set drop parameter default value to FALSE?

like image 372
Pop Avatar asked Nov 01 '22 14:11

Pop


1 Answers

`[` <- function(...) base::`[`(...,drop=FALSE)  

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

like image 138
Pork Chop Avatar answered Nov 08 '22 07:11

Pork Chop