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

  • Home
  • SEARCH
  • 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 8978359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:35:34+00:00 2026-06-15T19:35:34+00:00

Possible Duplicate: Basic lag in R vector/dataframe Trying to lag a variable in R

  • 0

Possible Duplicate:
Basic lag in R vector/dataframe

Trying to lag a variable in R but it isn’t working.

x<-1:10
y=lag(x,1)
xy=cbind(x,y)
View(xy)

    x   y
1   1   1
2   2   2
3   3   3
4   4   4
5   5   5
6   6   6
7   7   7
8   8   8
9   9   9
10  10  10

I am still not getting the lag. What am I doing wrong? Also is there a quicker way to combine to vectors/matrices without using cbind/rbind? For example

x=0:10
y=20:30
newxy=[x,y]

Thank you!

  • 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-15T19:35:35+00:00Added an answer on June 15, 2026 at 7:35 pm

    lag() expects a time series. (In R, class “ts” is the basic time-series class, used to represent data sampled at equispaced points in time. For more see ?ts.) So you can either convert x to a time-series, as demonstrated here, or make use one of the approaches suggested in another answer.

    x <- as.ts(1:10)
    y <- lag(x,1)
    xy <- cbind(x,y)
    xy
    #Time Series:
    #Start = 0 
    #End = 10 
    #Frequency = 1 
    #    x  y
    # 0 NA  1
    # 1  1  2
    # 2  2  3
    # 3  3  4
    # 4  4  5
    # 5  5  6
    # 6  6  7
    # 7  7  8
    # 8  8  9
    # 9  9 10
    #10 10 NA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Workaround for basic syntax not being parsed I am trying to allow
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I know its basic
Possible Duplicate: Absolute path & Relative Path This is a very basic question, but
Possible Duplicate: Random number generator not working the way I had planned (C#) I
Possible Duplicate: Workaround for basic syntax not being parsed I don't understand how to
Possible Duplicate: How would you implement a basic event-loop? Not really a language-specific question.
Possible Duplicate: padding is not working in Safari and IE in select list So
Possible Duplicate: 'AND' vs '&&' as operator Sorry for very basic question but I
Possible Duplicate: ASP.NET MVC on IIS 7.5 I am trying to deploy a basic
Possible Duplicate: Collection initialization syntax in Visual Basic 2008? This does not compile. Dim

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.