Dear R Experts,
This is the 2nd time in the chat room. Its a great place to get help from R
experts.
I have a data frame problem, it contains thousands of data.
part of it, I am giving for explaining the problem
date day x yz
82 1989-04-28 Fri 2118.0 2418.80 33713
Hi,
It's more a vector question. Try this one:
f
function( x, test = is.na(x) | x == 0 ){
out - x[!test][ cumsum(!test) ]
if(test[1]) out - c(NA,out)
out
}
f( c(1,0,2,1,0) )
[1] 1 1 2 1 1
f( c(1,0,2,1,0, NA) ) # missing values are also replaced
[1] 1 1 2 1 1 1
f( c(0,1,0,2,1,0)
On Sun, Apr 6, 2008 at 9:04 AM, saikat sarkar [EMAIL PROTECTED] wrote:
This is the 2nd time in the chat room. Its a great place to get help from R
experts.
I assume you are referring to this email list. I am not aware of
a chat room but if it exists that is something different from this
list.
There may well be neater ways to do this, but if you have only a
limited number of zeros in any run, this is probably as quick as
any. Suppose your data frame is 'dat':
fixCol - function(x) {
y - x
n - length(x)
while(any(zx - x == 0)) {
y - c(NA, y[-n])
4 matches
Mail list logo