[R] using reserved words in R, and reuse variable names in different functions
MacQueen, Don
macqueen1 at llnl.gov
Mon Mar 4 16:29:08 CET 2013
Yes, it can cause problems. And speaking for myself, I'd say it's not
worth the risk, because it's easy enough to find alternative variable
names that are close enough to the notation of your formulas that
remembering should be no problem. For example, "tt", "cc", and "mmatrix"
might do it.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 3/1/13 1:56 PM, "C W" <tmrsg11 at gmail.com> wrote:
Hi list,
I am writing several functions and running out variable names. I am using
words such as "t", "c", "matrix" to keep the notation same as formulas I am
using.
For example I have,
unnormalized <- function(t, x, y){
val <- rnorm(t, mean=x, var=y)
return(val)
}
metropolis <- function(t, c, x, y){
den1 <- unnormalized(t, mean=x, sd=y)
den2 <- unnormalized(c, mean=x, sd=y)
if(den1 < den2)
return(a)
else
return(b)
}
for(i in 1: 100){
matrix <- c()
matrix[i] <- metroplis(1, 2, 3, 4)
}
Here, I reused letter "t" and "c", and the word "matrix". Could this cause
any potential problems?
Thanks in advance,
Mike
[[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