[R] (no subject)
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Thu Jun 19 08:25:32 CEST 2008
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
More information about the R-help
mailing list