Reputation: 2164
I've been trying to extract something from a string (actually a $call) in R, and it's driving me nuts. If you have:
library(vars)
data <- as.data.frame(matrix(c(runif(40)), ncol=2))
z <- matrix(c(runif(40)), ncol=2)
var.modell <- VAR(data, p = 2, exogen=z, type = "trend")
How do you extract the z? I've tried googling and searching stack overflow. I found this: R extract a part of a string in R
which made me try:
sub(".*?exogen=(.*?)", "\\1", var.modell$call, perl = TRUE)
But it returns:
[1] "VAR" "data" "2" "trend" "z"
What am I doing wrong?
Upvotes: 1
Views: 319
Reputation: 42649
Look at the call
object itself:
m <- lm(speed~dist,data=cars)
m$call$data
## cars
You'll want var.modell$call$exogen
.
Upvotes: 3