[R] call a variable from outside of for loop

Rui Barradas ruipbarradas at sapo.pt
Tue Apr 23 14:09:58 CEST 2013


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.
>



More information about the R-help mailing list