Shifting a data frame in R

Viewed 13023

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??

5 Answers
Related