Displaying 20 results from an estimated 20000 matches similar to: "Using paste to create and evaluate a variable expression"
2003 Jan 31
2
Varying texts in expression(paste())
Hi,
I am using R a lot to make plots relating to radioactivity, I am often using
expression() to label the plots with nuclide names written with
superscripts, e.g.
expression(paste("Releases of ", { }^{99},Tc," (TBq/year)"))->ywtext
But, is there any simple way to change the number and name of the nuclide
through a variable? I tried
nuccode=expression({ }^{99},Tc)
1997 Aug 20
1
R-alpha: R-0.50-a3(+) Method despatching bug ?
It is very wierd... Can some of you confirm the following behavior ?
It is a new bug (feature ?) which was not yet in 0.49 ...
noquote <- function(obj) {
## constructor for a useful "minor" class
if(!inherits(obj,"noquote")) class(obj) <- c(class(obj),"noquote")
obj
}
"[.noquote" <- function (x, subs) structure(unclass(x)[subs], class =
2009 Sep 03
2
Recursion is slow
The following recursion is about 120 times faster in C#. I know R is not known for its speed with recursions but I'm wondering if anyone has a tip about how to speed things up in R.
#"T" is a vector and "m" is a number between 1 and sum(T)
A <- function(T,m) {
lt <- length(T)
if (lt == 1) {
if (0 <= m & m <= T[1]) {
return(1)
} else {
return(0)
}
2006 Nov 23
3
Conversion from expression to numeric
Dear All
I am trying to convert from the type "expression" to the type
"numeric". The following works:
> x <- expression(6.2)
> as.numeric(as.character(x))
[1] 6.2
However, the following does not work:
> x <- expression(62/100)
> as.numeric(as.character(x))
[1] NA
Warning message:
NAs introduced by coercion
Any idea about how to deal with the second case?
2012 Jul 03
2
"evaluating expressions" contained in a dataframe
#I have a dataframe called "tests" that contain "character expressions". These
characters are rules that use data from within another dataframe. Is there
any way within R I can access the rules in the dataframe called tests, and
then "evaluate" these "rules"?
#An example may better explain what I am trying to accomplish:
tests <-
2010 May 30
2
Question about package coin
Anyone know if coin can run a permutation test based on a (user-defined) statistic other than the mean difference? The function independence_test does the permutation t-test via difference in means. I'm wondering if it's possible to use independence_test to run a permutation test for some other statistic than the difference in means. For example, I'd like to run a permutation test
2006 Oct 27
2
all.names() and all.vars(): sorting order of functions' return vector
Dear list-subscriber,
in the process of writing a general code snippet to extract coefficients
in an expression (in the example below: 0.5 and -0.7), I stumbled over
the following peculiar (at least peculiar to me:-) ) sorting behaviour
of the function all.names():
> expr1 <- expression(x3 = 0.5 * x1 - 0.7 * x2)
> all.names(expr1)
[1] "-" "*" "x1"
2020 Nov 05
1
Named class vector
The source to the noquote() function looks like this:
noquote <- function(obj, right = FALSE) {
## constructor for a useful "minor" class
if(!inherits(obj,"noquote"))
class(obj) <- c(attr(obj, "class"),
if(right) c(right = "noquote") else "noquote")
obj
}
Notice what happens with right =
2011 Aug 22
1
looping with paste
Dear list,
I have a spacialPolygonDataFrame where variables were unnecessarily imported as factors. So I am trying to unfactor variables from spatialPolygonDataFrame at data with a loop
for (i in (1:length(names( spatialPolygonDataFrame)))){
command<-paste("spatialPolygonDataFrame$names(spatialPolygonDataFrame at data[",i,"])<-as.character(
2009 Mar 31
1
Problem with mathematical expression and loop
Hi to all
I use a loop to plot 9 different histograms of 9 different
transformations of one dataset (x).
I want to label the histograms with the mathematical expression of each
transformation (e.g. x^3). For that I've prepared a vector with the
labeling names for "expression".
> trans.expr <- c("x^3", "x^2", "x", "frac(1,x)",
2011 Jan 24
2
normality and equal variance testing
I currently have a program that automates 2-way ANOVA on a series of endpoints,
but before the ANOVA is carried out I want the code to test the assumptions of
normality and equal variance and report along with each anova result in the
output file. How can I do this?
I have pasted below the code that I currently use.
library(car)
numFiles = x #
2005 Jun 03
2
Everyone-- the scoop on Bison/Flex --
Hey, everybody---
Ignorance CAN be bliss, at least for a while, but, .... Just so you
know...
A week or two ago, some upgrades to the expression parser (you know, the
expressions you put in $[ ... ] in your extensions.conf file) that I
submitted, have been merged into the CVS HEAD of the source.
Hopefully, for around 99.9% of you, it won't make any difference to you.
The Makefile has also
2013 Apr 29
3
all.vars for nested expressions
Dear R fellows,
Assume I define
a <- expression(fn+tp)
sen <- expression(tp/a)
Now I'd like to know, which variables are necessary for calculating sen
all.vars(sen)
This results in a vector c(tp,a). But I'd like all.vars to evaluate the
sen-object down to the ground level, which would result in a vector
c(tp,fn) (because a was defined as fn+tp). In other words, I'd like
2009 Aug 11
1
Passing a list object to lapply
Hello,
I'm having difficulty passing an object name to a lapply function. Can
somebody tell me the trick to make this work?
#Works
T13702 <- TRACKDATA[["13702.xls"]][["data"]]
min(unlist(lapply(list(T13702), function(x) mdy.date(x[1, 2], x[1, 1],
x[1, 3]))))
16553
#Works
d<-2
assign(paste("T",substr(names(TRACKDATA)[d],1,(nchar(names(TRACKDATA)[d]
2014 May 01
3
How to test if an object/argument is "parse tree" - without evaluating it?
This may have been asked before, but is there an elegant way to check
whether an variable/argument passed to a function is a "parse tree"
for an (unevaluated) expression or not, *without* evaluating it if
not?
Currently, I do various rather ad hoc eval()+substitute() tricks for
this that most likely only work under certain circumstances. Ideally,
I'm looking for a isParseTree()
2009 Apr 07
3
write text file as output without quotes
Hi R,
When I use the below to write the text file
try=data.frame(rep("a",5), rep("b",5))
write.table(try,"z:\\try.txt",row.names=F,col.names=F,sep="\t")
the output contains two columns with quotes! Is there a way to write
without quotes?
I tried
try[,1]=noquote(try[,1])
try[,2]=noquote(try[,2])
Thank you,
Regards,
Ravi Shankar
2008 Jun 15
1
c.noquote() weirdness
I haven't been able to get anywhere tracking this down. It seems that c.noquote() does
something strange with its third (and subsequent) parameters:
R-2.7.0 under NetBSD, R-2.6.0 under Solaris, and R-2.8.0 (unstable) (2008-06-10 r45893)
under WinXP, I get:
> c(noquote('z'), 'y', 'x', '*')
[1] z y x * x *
>
or:
> c(noquote('z'),
2008 Feb 04
1
Concatenation and Evaluation
Hello all,
I've run into what I bet is a silly problem; however, I've been
trying to get around it now for a couple weeks and every time I think
I have the answer it still doesn't work. So I apologize in advance
if this is painfully obvious, but I've run out of ideas and would
really appreciate any input.
My situation is this, I'm importing a number of tab
2010 Dec 11
2
remove quotes from the paste output
Hi,
I'm generating the name of the variable with paste function and then using that
variable name further to get the specific position value from the data.frame,
here is the snippet from my code:
modelResults <- extractModelParameters("C:/PilotStudy/Mplus_Input/Test",
recursive=TRUE)
#extractModelParameters reads all the output files from the Test folder and
create the
2002 Jun 02
2
selections using text strings (result of noquote)
G'day all,
I am trying to use a string as an argument in a selection but things are
not working as I expect, seems the selection is not seeing the expanded
string and I do not know how to make it. Perhaps the noquote class value
that is returned is the problem.
Here is an example.
> selection #this is my string
[1] "attackprogress$Se=='Toona ciliata [19825: JMM35]'"