Hello. I have a vector and within that vector is one expression. When I display this vector it comes up as expression(NA_character_, NA_character_, "Null Effect", "Pooled effect", NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, paste("Het Contours ", I^2, sep = ""), 0.4, 0.41, 0.42, 0.45, NA_character_) Where the part in bold is the element which is an expression. How do I change this vector to a standard format what I can manipulate in the usual way? -- View this message in context: http://www.nabble.com/help-with-expression%28%29-tp25004374p25004374.html Sent from the R help mailing list archive at Nabble.com.
On Mon, 17 Aug 2009 12:24:28 +0200, deanj2k <dl120 at le.ac.uk> wrote:> > Hello. > I have a vector and within that vector is one expression. When I display > this vector it comes up as > > expression(NA_character_, NA_character_, "Null Effect", "Pooled effect", > NA_character_, NA_character_, NA_character_, NA_character_, > NA_character_, paste("Het Contours ", I^2, sep = ""), 0.4, > 0.41, 0.42, 0.45, NA_character_) > > Where the part in bold is the element which is an expression. How do I > change this vector to a standard format what I can manipulate in the > usual > way?Dude, I have no idea what kind of analysis you are mastering, but that kind of output does not smell good. Inside the expression you have a nested expression, so you have to iterate over. Here is a way to proceed:> te <- expression(NA_character_, NA_character_, "Null Effect", "Pooled > effect",NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, paste("Het Contours ", I^2, sep = ""), 0.4, 0.41, 0.42, 0.45, NA_character_)> I <- 3 > tl <- lapply(as.list(te), eval, envir=parent.frame()) > str(tl)List of 15 $ : chr NA $ : chr NA $ : chr "Null Effect" $ : chr "Pooled effect" $ : chr NA $ : chr NA $ : chr NA $ : chr NA $ : chr NA $ : chr "Het Contours 9" $ : num 0.4 $ : num 0.41 $ : num 0.42 $ : num 0.45 $ : chr NA>or if you want unevaluated paste expression just:> as.list(te)[[1]] [1] NA [[2]] [1] NA [[3]] [1] "Null Effect" [[4]] [1] "Pooled effect" [[5]] [1] NA [[6]] [1] NA [[7]] [1] NA [[8]] [1] NA [[9]] [1] NA [[10]] paste("Het Contours ", I^2, sep = "") [[11]] [1] 0.4 [[12]] [1] 0.41 [[13]] [1] 0.42 [[14]] [1] 0.45 [[15]] [1] NA>Vitalie. --
All of it is an expression (see ?expression). Maybe you'd better explain what exactly you're trying to do or what you mean by standard format and "usual way" (this part depends very much on what you're used to). You can manipulate parts of this expression, say, like this: foo <- expression(NA_character_, NA_character_, "Null Effect", "Pooled effect", NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, paste("Het Contours ", I^2, sep = ""), 0.4, 0.41, 0.42, 0.45, NA_character_) foo[[11]] <- 10000 foo[10] <- expression(cat("hello, ppl")) # note that foo[[10]] is a call, so you can manipulate it like the usual call objects are manipulated (i.e., the standard way :-). foo[10] is an expression, so you can manipulate it in another standard way. ... and you can convert it to a character vector or a list as.character(foo) as.list(foo) ... and you can `eval` the whole expression e.g. using sapply or lapply. sapply(foo, eval) # umm ... maybe not, because you refer to I there which is probably in your global # environment, so try sapply(foo, eval, envir=.GlobalEnv) KK On Mon, Aug 17, 2009 at 1:24 PM, deanj2k <dl120@le.ac.uk> wrote:> > Hello. > I have a vector and within that vector is one expression. When I display > this vector it comes up as > > expression(NA_character_, NA_character_, "Null Effect", "Pooled effect", > NA_character_, NA_character_, NA_character_, NA_character_, > NA_character_, paste("Het Contours ", I^2, sep = ""), 0.4, > 0.41, 0.42, 0.45, NA_character_) > > Where the part in bold is the element which is an expression. How do I > change this vector to a standard format what I can manipulate in the usual > way?> -- > View this message in context: > http://www.nabble.com/help-with-expression%28%29-tp25004374p25004374.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]