Re: [R] shifting data in matrix by n rows

2008-07-11 Thread Gabor Grothendieck
Just one additional item. Since I posted, an optional na.pad= argument has been added to lag.zooreg in the devel version of zoo with which the code reduces to: # next line grabs lag.zooreg from devel version of zoo source("http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/R/w

Re: [R] shifting data in matrix by n rows

2008-07-11 Thread rcoder
This is great! Thank you very much Gabor. rcoder Gabor Grothendieck wrote: > > See ?lag and in zoo ?lag.zoo. Both pages have > examples. Using lag.zoo here it is with your data: > > Lines <- "Date Apples Oranges Pears > 1/7 2 35 > 2/7 1 4

Re: [R] shifting data in matrix by n rows

2008-07-10 Thread Gabor Grothendieck
Actually my last reply will drop one row since its pushed off to beyond the data range. You can avoid that with zooreg: # from before for comparison lag(z, -1, na.pad = TRUE) # pure shift - note use of zooreg here # Unlike lag.zoo, lag.zooreg can shift beyond data range zr <- as.zooreg(z) lag(zr

Re: [R] shifting data in matrix by n rows

2008-07-10 Thread Gabor Grothendieck
See ?lag and in zoo ?lag.zoo. Both pages have examples. Using lag.zoo here it is with your data: Lines <- "Date Apples Oranges Pears 1/7 2 35 2/7 1 47 3/7 3 810 4/7 5 72 5/7 6 3

Re: [R] shifting data in matrix by n rows

2008-07-10 Thread rcoder
Hi everyone, Thanks very much for all your replies. I'm interested in hearing more about the lag function. I remember coming across this in the R intro manual, but I couldn't figure out how to apply it to my case. Does anyone know how it is applied, assuming a time series data frame? Thanks, r

Re: [R] shifting data in matrix by n rows

2008-07-09 Thread jim holtman
Is this what you want: > x <- read.table(textConnection("Date Apples Oranges Pears + 1/7 2 35 + 2/7 1 47 + 3/7 3 810 + 4/7 5 72 + 5/7 6 35"), header=TRUE) > closeAllCo

Re: [R] shifting data in matrix by n rows

2008-07-09 Thread Gabor Grothendieck
If its a zoo or ts time series you can use the lag function. On Wed, Jul 9, 2008 at 2:57 PM, rcoder <[EMAIL PROTECTED]> wrote: > > Hi everyone, > > I have some data in a matrix, and I want to shift it down by one row. The > matrix in question has a date column. Does anyone know of a way to shift t

Re: [R] shifting data in matrix by n rows

2008-07-09 Thread rcoder
Original Table: Date Apples Oranges Pears 1/7 2 35 2/7 1 47 3/7 3 810 4/7 5 72 5/7 6 35 What I want after shift (data shifted, dates left unchanged) Date Apples O

Re: [R] shifting data in matrix by n rows

2008-07-09 Thread jim holtman
Can you provide commented, minimal, self-contained, reproducible code. If you don't have code, at least provide a before/after version of the matrix that you would like. It is easy to use indexing to move stuff around, we just have to know what is it that you want to move. On Wed, Jul 9, 2008 at

[R] shifting data in matrix by n rows

2008-07-09 Thread rcoder
Hi everyone, I have some data in a matrix, and I want to shift it down by one row. The matrix in question has a date column. Does anyone know of a way to shift the data by one row, whilst preserving the date column in the matrix - i.e. shift the data and leave the date column in the current locat