[R] Is there a faster way to do this?

2010-03-25 Thread Márcio Resende
Hi guys, I am still learning R, and not well familiar with all the apply functions. I am trying to find faster alternatives to replace the for cycle. Is there a faster way to do the example below? nm - 1000 b - matrix (rnorm (5000, 0, 1), nrow = 500, ncol = nm) a - matrix (0, nm, nm) for (i in 1

Re: [R] Is there a faster way to do this?

2010-03-25 Thread Peter Alspach
. Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Márcio Resende Sent: Friday, 26 March 2010 2:15 p.m. To: r-help@r-project.org Subject: [R] Is there a faster way to do this? Hi guys, I am still learning R

Re: [R] Is there a faster way to do this?

2010-03-25 Thread RICHARD M. HEIBERGER
Márcio, Think matrix! Do you really want b to be 100 copies of the same numbers? You are asking for a strange crossproduct with the main diagonal zeroed out. a2 - crossprod(a) a2[cbind(1:1000, 1:1000)] - 0 all.equal(a, a2) Rich [[alternative HTML version deleted]]

Re: [R] Is there a faster way to do it?

2009-10-29 Thread Adaikalavan Ramasamy
You might also want to consider using na.string=9 in the scan(). jim holtman wrote: Here is a faster way of doing the replacement: (provide reproducible data next time) x - matrix(sample(6:9, 64, TRUE), 8) x [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]877678

[R] Is there a faster way to do it?

2009-10-28 Thread Marcio Resende
#Mdarts is a matrix 2343x788 #frequencia is a vector 2343x1 # 9 in Mdarts[fri,frj] stands for my missing values which i want to replace by the value in the vector frequencia Mdarts-t(matrix(scan(C:/GWS/CNB/dartg.txt),ncol=nindT,nrow=nm, byrow=T)) frequencia -

Re: [R] Is there a faster way to do it?

2009-10-28 Thread jim holtman
Here is a faster way of doing the replacement: (provide reproducible data next time) x - matrix(sample(6:9, 64, TRUE), 8) x [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]87767879 [2,]77867677 [3,]777696