[R] Count factor if

David Winsemius dwinsemius at comcast.net
Tue Feb 15 19:13:11 CET 2011


On Feb 15, 2011, at 12:18 PM, mathijsdevaan wrote:

>
> Thanks for your quick response. The solution that you propose comes  
> close to
> what I want, however by using 'FUN = order', the new variable is  
> based on
> its order rather than y< focal y. In the case of two similar rows
> (Xrow1=Xrow2 and Yrow1=Yrow2), the value of Zrow1 < Zrow2. Any  
> solutions?

First a suggestion. Please include context when following up on r- 
help. Nabble provides a simple method for doing so.

Here is a method that works despite generating a warning:

cbind(X, z = ave(X$y, X$x, FUN = seq) - 1)

>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Count-factor-if-tp3306856p3307164.html
> Sent from the R help mailing list archive at Nabble.com.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list