[R] call a variable from outside of for loop

Berend Hasselman bhh at xs4all.nl
Tue Apr 23 14:44:09 CEST 2013


On 23-04-2013, at 14:19, eliza botto <eliza_botto at hotmail.com> wrote:

> Dear Rui,it worked.......thanks indeed for you timely responce
> elisa
> 

In the original post you mentioned that e only held the first row.
But with what you showed I would have expected e to hold the last number printed.
So it's still unclear what you wanted to do or you didn't explain in enough detail what you were doing.
Which is why I asked for a reproducible example which you have not provided.

Berend

>> Date: Tue, 23 Apr 2013 13:09:58 +0100
>> From: ruipbarradas at sapo.pt
>> To: eliza_botto at hotmail.com
>> CC: r-help at r-project.org
>> Subject: Re: [R] call a variable from outside of for loop
>> 
>> Hello,
>> 
>> It seems that you're recreating the variable 'e' every time through the 
>> loop. In the end you only have 1 row. Try to create it outside the loop, 
>> like
>> 
>> e <- vector("list", 35)
>> 
>> Then inside the loop
>> 
>> e[[i]] <- print(...)
>> 
>> Hope this helps,
>> 
>> Rui Barradas
>> 
>> Em 23-04-2013 12:21, eliza botto escreveu:
>>> Dear useRs,
>>> While using print command in "for" loop, i designated a variable being printed by "e". Although the output was shown inside the loop but when i tried to call the variable outside the loop it only gave the first row, where as it should have 35 rows as it showed inside loop.The command which i used in the loop is
>>> e<-print(sum(abs(b-m[,i])))
>>> 
>>> Kindly help me on it..
>>> Eliza 		 	   		
>>> 	[[alternative HTML version deleted]]
>>> 
>>> ______________________________________________
>>> 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.
>>> 
> 		 	   		  
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list