Re: [R] (no subject)

From: Hans-Jörg Bibiko <bibiko_at_eva.mpg.de>
Date: Thu, 19 Jun 2008 08:25:32 +0200

On 19.06.2008, at 07:24, Paul Adams wrote:

> Hello everyone,
> I am wanting to replace an element in a matrix with NA. I have used
> the following code
> dat<-read.table(file="C:\\Documents and Settings\
> \....txt",header=T,row.names=1)
> file.show(file="C:\\Documents and Settings\\....txt")
> Z.matrix<-as.matrix(dat)
> Y<-dat[,46:63]
> X<-dat[1,51]
> dat[1,51]<-NA
> Whenever I use this code I get the original value when I type show
> (X).I run the script and type
> show(X) and the original value is still there.What am I doing wrong?

Well, actually nothing.
R works line by line. You set X<-dat[1,51] with let's say '4711'. Fine X is now '4711'. Then you change the cell dat[1,51]<-NA. Fine. If you type show(dat) you'll see that the cell 1,51 is now NA. But X is still the same, because X is NOT bound to the content of the cell dat[1,51].

--Hans



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. Received on Thu 19 Jun 2008 - 06:27:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 Jun 2008 - 07:31:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive