[R] help with expression()
Vitalie S.
vitosmail at rambler.ru
Mon Aug 17 18:43:13 CEST 2009
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.
--
More information about the R-help
mailing list