Hi,
when you do the trunc the mx is not a real integer 1 so you must round up

m<-matrix(data=NA, nrow=10,ncol=10)
i<-1001
mx<-round(trunc(i/1000))
my<-round((i/1000-mx)*1000)
m[mx,my]<-1
m
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
 [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
[10,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA

Chunhao Tu



Quoting Valentino Botta <[EMAIL PROTECTED]>:


the following code:

m<-matrix(nrow=10,ncol=10)
i<-1001
mx<-trunc(i/1000)
my<-(i/1000-mx)*1000
m[mx,my]<-1

does not assign the value at the matrix m[1,1]
Any hints?

Thanks
v

--
View this message in context: http://www.nabble.com/Matrix-set-value-problem-tp18253809p18253809.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.


______________________________________________
R-help@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.

Reply via email to