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
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
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,
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 -
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
: 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
.
-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
- 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
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
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
[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
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
-
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
13 matches
Mail list logo