Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:29:51+00:00 2026-06-11T17:29:51+00:00

The code: A <- matrix(NA, nrow = 10, ncol = 3) colnames(A) <- paste(‘trial’,

  • 0

The code:

A <- matrix(NA, nrow = 10, ncol = 3)
colnames(A) <- paste('trial', 1:3)

Let I want to name the third column with something different from trial 3: how may I?

Ok, now:

library(vars)
data(Canada)
var.2c <- VAR(Canada, p = 2, type = "const")
pred <- predict(var.2c, n.ahead = 8, ci = 0.95)

If I want to see the first value of pred, according to what predict method returns here, I have to input

> pred$fcst$e[1]
[1] 962.6557

You can see that I had to specify time series name e to obtain the value I wanted. If the code above was inserted into a function, it would not be possible to call pred$fcst$e[1] without specifying time series name, thereby it would not be possible to pass another time series data frame to our custom function.

Example: let X be a time series data frame. Then

pred.var <- function(X) {
   var.2c <- VAR(X, p = 2, type = 'const')
   pred <- predict(var.2c, n.ahead = 8, ci = .95)
   # return(pred$fcst$...) # Here lies the issue, because function must know X column name
}

As you can see from example above, function pred.var must know the name of the X column whose it must return the prediction but it cannot unless it is read from X.

Any idea?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:29:52+00:00Added an answer on June 11, 2026 at 5:29 pm

    You can access an element of a list either by $e or [["e"]], where in the second one, you can use any character variable. So these two things give the same value.

    pred$fcst$e[1]
    pred$fcst[[ colnames(Canada)[1] ]][1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please, input the following code: A <- matrix(11, nrow = 4, ncol = 3)
I want to write a parallel code that works on a 3D matrix where
Theoretically, let us assume we were to hard-code matrix multiplications for each different combination
I currently have the following code: type Matrix(sourceMatrix:double[,]) = let rows = sourceMatrix.GetUpperBound(0) +
This is the code for a matrix multiplication program ex implicit none real ::
In a C++ code I have a matrix of double variables which I print
I have the following code to convert the type of the matrix using cv::Mat.convertTo()
I've taken code from the MSDN page on Matrix Filters and modified it slightly.
I've been dealing with math-intensive code and require a good matrix library. I could
I am working with some code which outputs a 3x3 rotation matrix and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.