[R] Query: matrix definition

jim holtman jholtman at gmail.com
Mon Feb 21 14:25:11 CET 2011


By careful programming practices you should be able to avoid the
problem.  There is no way to prevent it since the program is only
doing what you ask it to do and if you make a mistake and ask it do to
something, it is not the program's fault.  One of the nice things (&
bad things) about R is that you can redefine what the object is on the
fly.

On Mon, Feb 21, 2011 at 7:50 AM, Stefano Sofia
<stefano.sofia at regione.marche.it> wrote:
> Dear list users,
> if within a function I first define a matrix
> mymat <- matrix(NA, nrow=m, ncol=n)
> and somewhere afterwards by mistake
> mymat <- c(1,2,3)
> this second command deletes the first one.
> How can I make sure that within the function mymat will always remain the matrix defined at the beginning, without possibility of changing it throughout the code?
> Secondly, is it possible to define mymat as a matrix of integers, with no possibility of loading real numbers?
>
> Thank you for your help
> Stefano Sofia
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della  DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list