Re: [R] Scope of variable?

From: Martyn Byng <Martyn.Byng_at_nag.co.uk>
Date: Wed, 16 Mar 2011 14:24:45 +0000

Hi,

Not sure what you are trying to do with the "cat" command, but cat returns an invisible NULL (as described in the doc), so

a = cat(a,v)

just sets a to NULL

Martyn

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Ravi Kulkarni
Sent: 16 March 2011 11:42
To: r-help_at_r-project.org
Subject: [R] Scope of variable?

I know this is a very elementary question... I could not find a solution looking at old posts.
I am unable to access a variable outside the scope of a for loop, even when
the variable was defined before the loop:

haar <- function() {
a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543)

for (i in c(1:100)) {

	m = matrix(rnorm(36)+1i*rnorm(36),6)
	qrm = qr(m)
	Q = qr.Q(qrm)
	eival = eigen(Q, only.values=T)
	ph = Arg(eival$values)
	v = Mod(ph)
	a = cat(a,v)		

}

hist(a)
}

The hist command does not plot because a is null there. How do I plot a? I tried using

                          assign("a", a, envir = .GlobalEnv)

but that does not help either... Neither did using <<- Any help is most welcome.
  Ravi

--
View this message in context:
http://r.789695.n4.nabble.com/Scope-of-variable-tp3381485p3381485.html
Sent from the R help mailing list archive at Nabble.com.

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

________________________________________________________________________
This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}}

______________________________________________
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.
Received on Wed 16 Mar 2011 - 14:36:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Mar 2011 - 14:40:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive