Displaying 20 results from an estimated 30000 matches similar to: "substitute question"
2003 Oct 21
5
do.call() and aperm()
Hi everyone
I've been playing with do.call() but I'm having problems understanding it.
I have a list of "n" elements, each one of which is "d" dimensional
[actually an n-by-n-by ... by-n array]. Neither n nor d is known in
advance. I want to bind the elements together in a higher-dimensional
array.
Toy example follows with d=n=3.
f <-
2003 Oct 23
3
what's going on here with substitute() ?
I was trying to create a function with a value computed at creation time,
using substitute(), but I got results I don't understand:
> this.is.R
Error: Object "this.is.R" not found
> substitute(this.is.R <- function() X,
list(X=!is.null(options("CRAN")[[1]])))
this.is.R <- function() TRUE
> # the above expression as printed is what I want for the
2004 Feb 17
5
pass by reference -- how to do it
Hello,
Pass by reference appears to be a topic which comes up
from time to time, but I wasn't able to find something in
the R-help archives which tells how to accomplish it.
I have a problem that you may have seen before -- R runs
out of memory when processing large matrices. Part of the
problem for me is that I am using some large matrices as
function arguments, and these are modified,
2003 Oct 17
7
datetime data and plotting
If I take the following simple data:
YEAR MONTH DAY WEIGHT.KG
2003 10 6 1.2
2003 10 12 1.2
2003 10 16 1.3
and format the date data and plot it:
dates <- strptime(paste(DAY,MONTH,YEAR),"%d%m%Y")
plot(c(min(dates),max(dates)),c(0,max(WEIGHT.KG)),
xlab="Date",ylab="Weight (kg)",type="n")
lines(dates,WEIGHT.KG)
points(dates,WEIGHT.KG)
I find that the
2005 Jun 22
1
substitute in a named expression
I have a 'named expression' like
expr <- expression(rep(1,d))
and would like to replace the argument d with say 5 without actually evaluating the expression. So I try substitute(expr, list(d=5)) in which case R simply returns expr which when I 'evaluate' it gives
eval(expr)
Error in rep.default(1, d) : invalid number of copies in rep()
I've looked at ?substitute and
2004 May 25
3
accessing function arguments as text, macro style
Hi. In a case like this, I can get strip headings that have the name
"c" and the value for c.
d <- data.frame(a=1:5,b=6:10,c=11:15)
> xyplot(a ~ b | paste("c", c), data=d)
>
For more complicated examples, instead of using paste repeatedly I
would like to use a function. It seems like what I really want is a
macro, though. I'm not quite familiar enough
2004 Mar 24
6
First Variable in lm
Hi all,
I just cannot think of how to do it:
I want to take the first variable (column) of a data frame and regress
it against all other variables.
bla <- function (dat) {
reg <- lm(whateverthefirstofthevariablenamesis ~., data=dat)
return(reg)
}
What kind of function do I have to take instead of the
whateverthefirstofthevariablenamesis,
eval(), substitute(), get(), ...
to
2010 Jan 29
2
evaluating expressions with sub expressions
Hallo
I'm having trouble figuring out how to evaluate an expression when one of
the variables in the expression is defined separately as a sub expression.
Here's a simplified example
mat <- expression(0, f1*s1*g1) # vector of formulae
g1 <- expression(1/Tm) # expansion of the definition of g1
vals <- data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for
2004 Dec 02
2
regex to match word boundaries
Can someone verify whether or not this is a bug.
When I substitute all occurrence of "\\B" with "X"
R seems to correctly place an X at all non-word boundaries
(whether or not I specify perl) but "\\b" does not seem to
act on all complement positions:
> gsub("\\b", "X", "abc def") # nothing done
[1] "abc def"
>
2005 Jun 09
1
single assignment affecting multiple sub-structures (PR#7924)
I'm trying to create a language structure that is a call to a function
with a number of arguments that is only known at run time. I do this by
using repeated indices to expand out a call with a single argument.
However, when I change one of the arguments, all are changed.
I don't see the same behavior when I initially create a call with
multiple arguments.
Even more strangely,
2004 Aug 18
5
labeled break statements in R?
Hi,
Are there labeled break statements in R? i.e., something along the
lines of
TOPLOOP: for(i in 1:m) {
for(j in 1:n) {
...
if(condition) {
break TOPLOOP
}
}
}
Thanks,
Roger
2003 Oct 08
6
Why does a[which(b == c[d])] not work?
Dear list,
I can not understand why the expression in
the subject does not work correct:
> dcrn[which(fn == inve[2])]
numeric(0)
> inve[2]
[1] 406.7
> dcrn[which(fn == 406.7)]
[1] 1.3994e-07 1.3988e-07 1.3953e-07 1.3966e-07 1.3953e-07 1.3968e-07
Is this a kick self problem or an bug?
Thaks very much
Thomas
2003 Nov 05
1
save(iris,file=
I tried it using file and it seems to work for saving:
> data(iris)
> con <- file("clipboard","w")
> save(iris,ascii=T,file=con)
> close(con)
> readLines("clipboard")
... lengthy output follows which seems correct ...
but not for loading:
> con <- file("clipboard","r")
> load(con)
Error in load(con) : loading from
2004 Jan 14
2
automatic "paste" filter to paste only the commands from a transcript on the clipboard
Just for fun (and actually because I would use it too) I wrote a
version of the "paste" menu command that assumes the clipboard
contains a transcript, and just pastes the commands from it into
the R console window (Windows GUI only).
So, if something like this:
> foo <-
+ 33
> foo * 3
[1] 99
> foo
[1] 33
is on the clipboard, then the "paste commands" menu
2002 Oct 10
2
tapply for matrices
Does anyone have something like tapply that is extremely fast for matrices when there is a very large number of levels of the grouping variable?
I'm referring to, for example,
tapply(x, grouping.variable, function.operating.on.submatrix)
where x is a matrix and the submatrix is a subset of the rows of x. The grouping variable's length equals the number of rows of x.
--
Frank E
2004 Sep 29
2
defining a template for functions via do.call and substitute.
Hi,
Given a function
fun <- function(a, b) a + b
how do I generate the function 'function(x, y) x + y'?
Working from the help files and Bill Venables' R-news article (June 2002),
I have tried various permutations with substitute without success.
e.g.
do.call("substitute", list(fun, list(a = as.name("x"), b = as.name("y"))))
Regards,
John.
2004 Aug 28
6
model.matrix.default chokes on backquote (PR#7202)
Full_Name: Gabor Grothendieck
Version: R version 1.9.1, 2004-08-03
OS: Windows XP
Submission from: (NULL) (207.35.143.52)
The following gives an error:
> `a(b)` <- 1:4
> `c(d)` <- (1:4)^2
> lm(`a(b)` ~ `c(d)`)
Error in model.matrix.default(mt, mf, contrasts) :
model frame and formula mismatch in model.matrix()
To fix it replace this line in model.matrix.default:
2003 Oct 31
4
Array Dimension Names
I would like to reference array dimensions by name in an apply and a summary
function. For example:
apply(x, "workers", sum)
Is there a better way to do this than creating a new attribute for the array
and then creating new methods for apply and summary? I don't want to name
the individual elements of each dimension (such as with dimnames) but rather
name the dimensions. Thanks
2005 Mar 18
4
Is a .R script file name available inside the script?
Hi,
if we have a file called Rscript.R that contains the following, for example:
x <- 1:100
outfile = "Rscript.Rout"
sink(outfile)
print(x)
and then we run
>> source("Rscript.R")
we get an output file called Rscript.Rout - great!
Is there an internal variable, something like .Platform, that holds
the script name when it is being executed? I would like to use
2003 Oct 16
4
data() misbehaving inside a function
Calls of the form data(package = pkg) inside a function
incorrectly fail ("pkg" is a local variable). For instance,
foo <- function(pkg) data(package = pkg)
foo("base")
Error in .find.package(package, lib.loc, verbose = verbose) :
none of the packages were found
## workaround -- force argument "package" to be an expression
## (not a