[R] Why does `[<-.matrix` not exist in base R

David Disabato dd|@@b01 @end|ng |rom gm@||@com
Sat Nov 23 17:58:42 CET 2019


Whenever going from working with a data.frame to a matrix, I get annoyed
that I cannot assign and subset at the same time with matrices - like I can
with data.frames.

For example, if I want to add a new column to a data.frame, I can do
something like `myDataFrame[, "newColumn"] <- NA`.

However, with a matrix, this syntax does not work and I have to use a call
to `cbind` and create a new object. For example, `mymatrix2 <-
cbind(mymatrix, "newColumn" = NA)`.

Is there a programming reason that base R does not have a matrix method for
`[<-` or is it something that arguably should be added?

-- 
David J. Disabato, Ph.D.
Postdoctoral Research Scholar
Kent State University
ddisab01 using gmail.com

Email is not a secure form of communication as information and
confidentiality cannot be guaranteed. Information provided in an email is
not intended to be a professional service. In the case of a crisis or
emergency situation, call 911.

	[[alternative HTML version deleted]]



More information about the R-help mailing list