Try this:

do.call(rbind, strsplit(gsub("010", "000", apply(temp, 1, paste, collapse =
"")), NULL))

On Wed, Sep 17, 2008 at 4:50 PM, Stacey Burrows <[EMAIL PROTECTED]>wrote:

> Dear R-users,
>
> I have some very simple data where 1's represent events and zeroes
> non-events, e.g.
> temp <- rbind(c(0,1,0,0,1,1,1,0), c(0,0,0,1,0,0,0,0))
>
> For each row in the matrix, I would like to replace a singelton event by a
> 0. That is, any 1 surrounded by zeroes (010) should be replaced by a zero
> (000). Sequences of 1's should be left unchanged.
>
> So the modified matrix shoud look like this:
> 00001110
> 00000000
>
> How can I do this in R?
>
> Thanks,
> Stacey
>
>
>
>      __________________________________________________________________
> [[elided Yahoo spam]]
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to