<div dir="ltr"><div><div><div><div><div><div>Use tanto no write.table() quanto no read.table() a função paste0() para gerar o nome variando conforme i:<br><br></div>> write.table(Y, paste0(i, '"txt"))<br><br></div>E para ler:<br><br></div>BD_i <- read.table(paste0(i, ".txt") header = TRUE)<br><br></div>Espero ter ajudado.<br><br></div>att,<br></div>FH<br><div><div><div><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2017-03-23 5:56 GMT-06:00 Adriele Giaretta Biase via R-br <span dir="ltr"><<a href="mailto:r-br@listas.c3sl.ufpr.br" target="_blank">r-br@listas.c3sl.ufpr.br</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br clear="all"><div><p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Olá
pessoal,<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><font face="times new roman, serif"><span style="font-size:12pt">eu
estou trabalhando no R com conjunto de dados muito grande (numa fase de
teste) e a tendência é que essa banco de dados aumente ainda mais, numa </span><span style="font-size:16px">próxima</span><span style="font-size:12pt"> etapa que não será teste. E em algumas
de minhas programações, o R retornou mensagem de aviso dizendo que não podia
alocar o vetor de tamanho de 3.7 GB.</span><span style="font-size:12pt"></span></font></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Dessa
forma, ao invés de concatenar uma matriz em baixo da outra num objeto criado
(onde ele me retorna que não foi capaz de armazenar tudo), eu gostaria de ir
salvando cada matriz gerada de resultado no diretório local.<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Minha
dúvida, é como criar esse algoritmo de forma que eu consiga salvar dentro de um
loop, data.frames com nomes diferentes, sem que ocorra substituição de um
data.frame pelo outro.<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Eu
criei um código mínimo (de forma que vocês possam me dar alguma ajuda), e eu
possa adaptar para a situação que estou trabalhando. Esse código está
substituindo o data.frame a cada rodada dentro do loop. Eu queria que o nome do
data.frame alterasse para que guardasse todos os resultados com nomes
diferentes, acompanhando a variação do loop (1,2, ..., N):<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">library(MASS)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">salva_BD_i
<- function(N){<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> for (i in 1:N){<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> p
<- 30 # numero de variáveis
a serem geradas (p)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> ME
<- rep(1, p)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> rho
<- 0.5 # correlacao <span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> sigma2 <- 1<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> sigma
<- sigma2 * ((1-rho)*diag(p)+rho*matrix(1, p, p))<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> n <- 10000<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> Y
<- mvrnorm(n, ME, sigma)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> </span><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US">write.table(Y,
"i.txt")<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> </span><span style="font-size:12pt;font-family:"times new roman",serif">}<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">}<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">N=30000<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">salva
= salva_BD_i(N)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:35.4pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Numa
segunda etapa, eu precisaria de ler (puxar todos os data.frame para dentro de
um objeto do R, num loop. Também criei um código mínimo executável, mas
acontece o mesmo, o índice do loop não é processado dentro do read.table:<span></span></span></p>
<pre style="line-height:11.25pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;word-break:break-all"><span class="m_-3674851022234929062gmail-gghfmyibcpb"><span style="font-family:"lucida console";color:blue" lang="EN-US">> </span></span><span class="m_-3674851022234929062gmail-gghfmyibcob"><span style="font-family:"lucida console";color:blue" lang="EN-US">setwd('C:\\Users\\Adriele\\ teste')</span></span><span style="font-family:"lucida console";color:black" lang="EN-US"><span></span></span></pre>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:11.25pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;word-break:break-all"><span style="font-size:10pt;font-family:"lucida console";color:blue" lang="EN-US">> dir()<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:11.25pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;word-break:break-all"><span style="font-size:10pt;font-family:"lucida console";color:black" lang="EN-US"> [1]
"1.txt" "2.txt" "3.txt" "4.txt" "5.txt" "6.txt" "7.txt" "8.txt" "9.txt" "10.txt" "Adriele.R"<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Leia_BD_i
<- function(N){<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"> </span><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US">aux= c()<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> for (i in
1:N){<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> BD_i <-
read.table("i.txt", header =
TRUE)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> media =
apply(BD_i, 2, mean)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> aux =
rbind(aux, media)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> }<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif" lang="EN-US"> return(medias
= aux)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">}<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">N=10<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><span style="font-size:12pt;font-family:"times new roman",serif">Leitura
= Leia_BD_i(N)<span></span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal"><br></p>
<pre style="line-height:11.25pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;word-break:break-all"><span class="m_-3674851022234929062gmail-gghfmyibgob"><span style="font-family:"lucida console";color:rgb(197,6,11)" lang="EN-US">Error in file(file, "rt") : cannot open the connection<span></span></span></span></pre><pre style="line-height:11.25pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;word-break:break-all"><span class="m_-3674851022234929062gmail-gghfmyibgob"><span style="font-family:"lucida console";color:rgb(197,6,11)" lang="EN-US">In addition: Warning message:<span></span></span></span></pre><pre style="line-height:11.25pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;word-break:break-all"><span class="m_-3674851022234929062gmail-gghfmyibgob"><span style="font-family:"lucida console";color:rgb(197,6,11)" lang="EN-US">In file(file, "rt") : cannot open file 'i.txt': No such file or directory</span></span><span style="font-family:"lucida console";color:black" lang="EN-US"><span></span></span></pre></div><font face="times new roman, serif"><span style="font-size:16px">Agradeço se alguém puder contribuir,</span></font><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- <br><div class="m_-3674851022234929062gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div style="font-family:times,serif;margin:0cm 0cm 0.0001pt;font-size:16px"><span style="white-space:pre-wrap"> </span>Adriele Giaretta Biase.</div><div style="font-family:times,serif;margin:0cm 0cm 0.0001pt;font-size:16px"><span style="white-space:pre-wrap"> </span>Mestre em Estatística e Experimentação Agropecuária - UFLA. <br><span style="white-space:pre-wrap"> </span>Doutora em Estatística e Experimentação Agronômica - ESALQ/ USP</div><div style="font-family:times,serif;margin:0cm 0cm 0.0001pt;font-size:16px"><span style="font-size:12pt;white-space:pre-wrap"> </span><span style="font-size:12pt">Contato: (19) 98861-0619.</span></div></div></div></div></div></div>
</div></font></span></div>
<br>______________________________<wbr>_________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>
<a href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br" rel="noreferrer" target="_blank">https://listas.inf.ufpr.br/<wbr>cgi-bin/mailman/listinfo/r-br</a><br>
Leia o guia de postagem (<a href="http://www.leg.ufpr.br/r-br-guia" rel="noreferrer" target="_blank">http://www.leg.ufpr.br/r-br-<wbr>guia</a>) e forneça código mínimo reproduzível.<br></blockquote></div><br></div></div></div></div></div></div></div></div></div>