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
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
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
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
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
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
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
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
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
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
10 matches
Mail list logo