Re: [R] efficiently replacing values in a matrix

2008-04-18 Thread Matthew Keller
Nanmdi, I think this is simply because a lot of time is taken transforming the matrix from logical (default when you create it) to numeric (when you add the number to [1,1]. If you do the same thing again to [1,2], it is done instantaneously: > a <- matrix(nrow=1,ncol=1) > system.time(a[1,

Re: [R] efficiently replacing values in a matrix

2008-04-18 Thread Nnamdi
Still it is pretty slow when entering values into a large matrix. Case in point: > a <- matrix(nrow=1,ncol=1) > system.time(a[1,1] <- 1903908.80385) user system elapsed 30.840 6.226 41.416 > is.matrix(a) [1] TRUE Is there a better way to enter values into large matrices? If I hav

Re: [R] efficiently replacing values in a matrix

2008-04-17 Thread Joerg van den Hoff
On Wed, Apr 16, 2008 at 03:56:26PM -0600, Matthew Keller wrote: > Yes Chuck, you're right. > just a comment: > Thanks for the help. It was a data.frame not a matrix (I had called > as.matrix() in my script much earlier but that line of code didn't run > because I misnamed the object!). My bad. T

Re: [R] efficiently replacing values in a matrix

2008-04-17 Thread Jim Lemon
Rolf Turner wrote: > On 17/04/2008, at 9:33 AM, Charles C. Berry wrote: > > > >>I'll lay odds that Matthew's 'matrix' is actually a data.frame, and >>I'll not be surprised if the columns are factors. > > > > > I suspect that you're right. > > ***Why*** can't people distinguish

Re: [R] efficiently replacing values in a matrix

2008-04-16 Thread Matthew Keller
Yes Chuck, you're right. Thanks for the help. It was a data.frame not a matrix (I had called as.matrix() in my script much earlier but that line of code didn't run because I misnamed the object!). My bad. Thanks for the help. And I'm VERY relieved R isn't that inefficient... Matt On Wed, Apr 16

Re: [R] efficiently replacing values in a matrix

2008-04-16 Thread Rolf Turner
On 17/04/2008, at 9:33 AM, Charles C. Berry wrote: > I'll lay odds that Matthew's 'matrix' is actually a data.frame, and > I'll not be surprised if the columns are factors. I suspect that you're right. ***Why*** can't people distinguish between data frames and matrices? If

Re: [R] efficiently replacing values in a matrix

2008-04-16 Thread Charles C. Berry
On Thu, 17 Apr 2008, Rolf Turner wrote: > > On 17/04/2008, at 7:52 AM, Matthew Keller wrote: > >> Hello all, >> >> I should probably know this by now... Anyway: >> >> I have a large matrix (dim(data) is 3000 18000). In each element are >> one of the following character strings "0/0", "1/1", "1/2"

Re: [R] efficiently replacing values in a matrix

2008-04-16 Thread Rolf Turner
On 17/04/2008, at 7:52 AM, Matthew Keller wrote: > Hello all, > > I should probably know this by now... Anyway: > > I have a large matrix (dim(data) is 3000 18000). In each element are > one of the following character strings "0/0", "1/1", "1/2", "2/2". I > wanted to replace "0/0" with NA and th

[R] efficiently replacing values in a matrix

2008-04-16 Thread Matthew Keller
Hello all, I should probably know this by now... Anyway: I have a large matrix (dim(data) is 3000 18000). In each element are one of the following character strings "0/0", "1/1", "1/2", "2/2". I wanted to replace "0/0" with NA and the other three with 0,1,2 respectively. To accomplish just the f