using EViews 7.1
I would like to access R for a certain bootstrap procedure and I am using the new EViews to R interface. I have problems finding books on this topic or documents on the internet. In particular, I cannot figure out how to get a matrix from R back into EViews using the xget command. Although xget(name = var1, type = vector) works fine, a similar version using xget(name = var1, var2 , type = matrix) does not work. It appears that I have a syntax error in the names argument.
Here is an example code:
!n = 1000
xopen(type=r, case=lower)
xrun "library(meboot)"
xrun "if (sum(.packages(TRUE)==""meboot"")==0) install.packages(""meboot"")"
xrun var1 <- rnorm(!n,0,1)
xrun var2 <- rnorm(!n,0,2)
xrun vars2 <- cbind(rep(1:2,rep(!n,2)),c(var1, var2))
xrun z<- meboot.pdata.frame(na.omit(vars2), reps = 20, trim=0.1, reachbnd = FALSE, expand.sd = FALSE, force.clt = TRUE, elaps = FALSE, colsubj= 1, coldata = 2)
xget(name = test1, test2 , type = matrix) z[,1:2] 'this does not work
'xget(name = test1 , type = vector) z[,1] this works but I want a matrix (there are many columns so vector by vector extraction would be inefficient
xclose
any help is greatly appreciated
Zeno
R and Eviews: using xget
Moderators: EViews Gareth, EViews Moderator
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: R and Eviews: using xget
If I'm understanding your question correctly, you should simply extract into the matrix using a single name ("test1"), not multiples ("test1 test2"). It will put the R matrix into an EViews matrix.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13586
- Joined: Tue Sep 16, 2008 5:38 pm
Re: R and Eviews: using xget
I think, perhaps, he was trying to put the R matrix into multiple named EViews vectors in one step, which I think we don't support. You can bring it into EViews as a matrix, then extract the columns as vectors in a for loop though.
Re: R and Eviews: using xget
I was trying to do the simple thing as Glenn suggested: just get the R matrix and convert it into an EViews matrix. The reason I was trying xget(name = test1, test2 , type = matrix) z[,1:2] is that I get the following error message: "The number of objects found do not match the number of names specified in name option (1 name(s) / 2 object(s))."
From the error message I understand that xget is looking for two names here.
However, I get the same error message using only one name argument.
thanks
Zeno
From the error message I understand that xget is looking for two names here.
However, I get the same error message using only one name argument.
thanks
Zeno
-
EViews Steve
- EViews Developer
- Posts: 844
- Joined: Tue Sep 16, 2008 3:00 pm
- Location: Irvine, CA
Re: R and Eviews: using xget
Zeno:
Your z object is a data.frame that has column names with spaces in their names (e.g. "Pseries 1"). This is allowed in R but EViews will not support that currently -- we'll have to fix that in a future patch. There is a workaround though...
Your command:
is getting a name count error because when EViews looks at the R object named "z[,1:2]", R is reporting that it is a data.frame with 2 columns, and the column names still have spaces in them. However, you can tell R to read the data.frame as a matrix like this:
With the "as.matrix", EViews will see your expression as a single matrix instead of a data.frame with two separate columns. And in this case, you only need to specify a single EViews name.
Steve
Your z object is a data.frame that has column names with spaces in their names (e.g. "Pseries 1"). This is allowed in R but EViews will not support that currently -- we'll have to fix that in a future patch. There is a workaround though...
Your command:
Code: Select all
xget(name = test1, test2 , type = matrix) z[,1:2]Code: Select all
xget(name=test1, type=matrix) "as.matrix(z[,1:2])"Steve
Re: R and Eviews: using xget
Great! Thanks for the solution.
-
EViews Steve
- EViews Developer
- Posts: 844
- Joined: Tue Sep 16, 2008 3:00 pm
- Location: Irvine, CA
Re: R and Eviews: using xget
By the way, I should've pointed out that whenever you want to read a data.frame with multiple columns into a single EViews matrix, you'll ALWAYS have to use the "as.matrix" conversion function, regardless if their column names have spaces in them or not.
EViews will always treat data.frames (or partial data.frames) as potentially multiple series or vector objects, each with their own name.
In regards to our documentation, it was always our intent on publishing a specific whitepaper on EViews/R integration that had more specifics than what is already in the User's Guide, but I haven't been able to get to it yet. I'll try to write this documentation as soon as possible, but I can't make any promises.
In the meantime, you can continue to ask questions in our forums and refer to older forum posts regarding this topic (there have been several already).
Steve
EViews will always treat data.frames (or partial data.frames) as potentially multiple series or vector objects, each with their own name.
In regards to our documentation, it was always our intent on publishing a specific whitepaper on EViews/R integration that had more specifics than what is already in the User's Guide, but I haven't been able to get to it yet. I'll try to write this documentation as soon as possible, but I can't make any promises.
In the meantime, you can continue to ask questions in our forums and refer to older forum posts regarding this topic (there have been several already).
Steve
Return to “General Information and Tips and Tricks”
Who is online
Users browsing this forum: No registered users and 1 guest
