Re: [R] Imputing missing values in time series

2007-06-25 Thread Achim Zeileis
On Fri, 22 Jun 2007, Horace Tso wrote: Thanks to Mark and Erik for different versions of locf, also Erik's pointer to archive where I found another function due to Simon Fear. I haven't tested the zoo locf function. Just as an addition to what Marc already wrote: zoo offers at least two

[R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
Folks, This must be a rather common problem with real life time series data but I don't see anything in the archive about how to deal with it. I have a time series of natural gas prices by flow date. Since gas is not traded on weekends and holidays, I have a lot of missing values, FDate Price

Re: [R] Imputing missing values in time series

2007-06-22 Thread Erik Iverson
I think my example should work for you, but I couldn't think of a way to do this without an interative while loop. test - c(1,2,3,NA,4,NA,NA,5,NA,6,7,NA) while(any(is.na(test))) test[is.na(test)] - test[which(is.na(test))-1] test [1] 1 2 3 3 4 4 4 5 5 6 7 7 Horace Tso wrote: Folks,

Re: [R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
Erik, indeed it gets the work done. I was hoping to avoid the dreaded looping, though. Thanks. Horace Erik Iverson [EMAIL PROTECTED] 6/22/2007 12:01 PM I think my example should work for you, but I couldn't think of a way to do this without an interative while loop. test -

Re: [R] Imputing missing values in time series

2007-06-22 Thread Leeds, Mark \(IED\)
PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson Sent: Friday, June 22, 2007 3:02 PM To: Horace Tso Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Imputing missing values in time series I think my example should work for you, but I couldn't think of a way to do this without an interative

Re: [R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
: Friday, June 22, 2007 3:02 PM To: Horace Tso Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Imputing missing values in time series I think my example should work for you, but I couldn't think of a way to do this without an interative while loop. test - c(1,2,3,NA,4,NA,NA,5,NA,6,7,NA) while(any(is.na

Re: [R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson Sent: Friday, June 22, 2007 3:02 PM To: Horace Tso Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Imputing missing values in time series I think my example should work for you, but I couldn't think

Re: [R] Imputing missing values

2004-09-02 Thread Jan Smit
- Original Message - From: Jan Smit [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 01, 2004 10:43 AM Subject: [R] Imputing missing values Dear all, Apologies for this beginner's question. I have a variable Price, which is associated with factors Season

[R] Imputing missing values

2004-09-01 Thread Jan Smit
Dear all, Apologies for this beginner's question. I have a variable Price, which is associated with factors Season and Crop, each of which have several levels. The Price variable contains missing values (NA), which I want to substitute by the mean of the remaining (non-NA) Price values of the

RE: [R] Imputing missing values

2004-09-01 Thread Manoj - Hachibushu Capital
How about the following code below? Price[is.na(price)] = mean(Price[-which(is.na(price))]); HTH Manoj -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jan Smit Sent: Wednesday, September 01, 2004 5:44 PM To: [EMAIL PROTECTED] Subject: [R] Imputing

Re: [R] Imputing missing values

2004-09-01 Thread Dimitris Rizopoulos
[EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 01, 2004 10:43 AM Subject: [R] Imputing missing values Dear all, Apologies for this beginner's question. I have a variable Price, which is associated with factors Season and Crop, each of which have several levels. The Price

Re: [R] Imputing missing values

2004-09-01 Thread Mahbub Latif
Try this: newPrice = unlist(sapply(Price, Crop:Season, function(x){ x[is.na(x)]=mean(x,na.rm=T); return(x); })) --- Jan Smit [EMAIL PROTECTED] wrote: Dear all, Apologies for this beginner's question. I have a variable Price, which is associated with factors Season and

Re: [R] Imputing missing values

2004-09-01 Thread Frank E Harrell Jr
- From: Jan Smit [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 01, 2004 10:43 AM Subject: [R] Imputing missing values Dear all, Apologies for this beginner's question. I have a variable Price, which is associated with factors Season and Crop, each of which have several levels