<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">It is bad practice to keep growing objects like 'd' in the loop. Here is a modified version that runs in under 1 second.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">> > # Read the text file (512x512)<br>> df<-matrix(runif(512 * 512), 512)<br>> my.stats('start')<br>start (1) - Rgui : 08:19:36 <282.7 415537.0> 415537.0 : 108.9MB<br>> d=matrix(NA,512 * 512, 3) # create output matrix<br>> for (i in 0:511){<br>+ for (j in 0:511){<br>+ d[i * 512 + j + 1,] <- c(i,j,df[i+1,j+1])<br>+ # Myrow<-c(i,j,df[i+1,j+1])<br>+ # d=rbind(d,Myrow)<br>+ }<br>+ }<br>> my.stats('done')<br>done (1) - Rgui : 08:19:37 <283.9 415538.1> 415538.1 : 164.9MB<br>> head(d, 10)<br> [,1] [,2] [,3]<br> [1,] 0 0 0.72414660<br> [2,] 0 1 0.26716396<br> [3,] 0 2 0.11328281<br> [4,] 0 3 0.05107802<br> [5,] 0 4 0.44158025<br> [6,] 0 5 0.09608051<br> [7,] 0 6 0.18925725<br> [8,] 0 7 0.64978998<br> [9,] 0 8 0.51816944<br>[10,] 0 9 0.83320742<br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"></div><div class="gmail_default" style="font-family:monospace,monospace"></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><br>Jim Holtman<br>Data Munger Guru<br> <br>What is the problem that you are trying to solve?<br>Tell me what you want to do, not how you want to do it.</div></div>
<br><div class="gmail_quote">On Tue, Jan 5, 2016 at 7:06 AM, hello_R <span dir="ltr"><<a href="mailto:shariful@excite.com" target="_blank">shariful@excite.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
I have a dataframe (512x512). I just want to create a new dataframe from it.<br>
I used the following code. It does not stop running! Could you please help.<br>
Thanks<br>
<br>
# Read the text file (512x512)<br>
df<-read.table("out_1_1.txt")<br>
<br>
d=NULL<br>
for (i in 0:511){<br>
for (j in 0:511){<br>
Myrow<-c(i,j,df[i+1,j+1])<br>
d=rbind(d,Myrow)<br>
}<br>
}<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://r.789695.n4.nabble.com/Simpe-script-does-not-finish-tp4716161.html" target="_blank" rel="noreferrer">http://r.789695.n4.nabble.com/Simpe-script-does-not-finish-tp4716161.html</a><br>
Sent from the datatable-help mailing list archive at Nabble.com.<br>
_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank" rel="noreferrer">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
</blockquote></div><br></div>