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 6017511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:08:20+00:00 2026-05-23T03:08:20+00:00

i have a data frame like this A B value 1 1 0.123 2

  • 0

i have a data frame like this

A B value
1 1 0.123
2 1 0.213
3 1 0.543
1 2 0.313
2 2 0.123
3 2 0.412

what i want to do is to create a function that shift this data frame by a value. for example:

if the value of shifting is 1 the data frame will become:

A B value
3 2 0.412
1 1 0.123
2 1 0.213
3 1 0.543
1 2 0.313
2 2 0.123

etc…

the function should be like this.

shift<-function(dataframe,shiftvalue)

is there any simple way to do this in R without entering in a lot of loops??

  • 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-05-23T03:08:21+00:00Added an answer on May 23, 2026 at 3:08 am

    You can do it many ways, but one way is to use head and tail:

    df <- data.frame(a=1:10, b = 11:20)
    
    shift <- function(d, k) rbind( tail(d,k), head(d,-k), deparse.level = 0 )
    
    
    > shift(df,3)
        a  b
    4   4 14
    5   5 15
    6   6 16
    7   7 17
    8   8 18
    9   9 19
    10 10 20
    1   1 11
    2   2 12
    3   3 13
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a data frame that contains a data like this : V1 V2
I have data that looks like this: entities id name 1 Apple 2 Orange
Possible Duplicate: Extracting indices for data frame rows that have MAX value for named
I have data that looks like CUSTOMER, CUSTOMER_ID, PRODUCT ABC INC 1 XYX ABC
If I have data like this: Key Name 1 Dan 2 Tom 3 Jon
I have a data frame with columns that, when concatenated (row-wise) as a string,
hii every one i have created a data entry screen like this in which
I have data in this form, Article ID Company A Company B Company C
I have data from a table in a database (string) that contain text and
I have data that needs to be executed on a certain background thread. I

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.