Re: [R] Matrix set value problem

From: <ctu_at_bigred.unl.edu>
Date: Thu, 03 Jul 2008 04:38:40 -0500

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 <bvalen_at_alice.it>:

>
> 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_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.
>



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 03 Jul 2008 - 10:05:00 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 03 Jul 2008 - 11:31:01 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