In two steps, you could use ave() to split by hour and find the
maximum of price and then use an ifelse clause on the resulting vector
to see when that actually equals the given price and assign "Y"/"N"
appropriately,

I'll leave the implementation as an exercise to the reader :-)

Best,
Michael

On Thu, Jun 7, 2012 at 9:17 AM, jcrosbie <ja...@crosb.ie> wrote:
> For a given hour I want to be able to  add a new column called flag.  The
> flag column will flag the highest price in a given hour.  Is there a way to
> do this without a loop?
>
> matrix:
> Unit,   Day,    Hour,   Price,  Flag
> afd1    1/2/2003        1       1       N
> afd1    1/2/2003        1       2       N
> afd1    1/2/2003        1       3       N
> afd1    1/2/2003        1       4       Y
> dcf1    1/2/2003        2       2       N
> dcf1    1/2/2003        2       3       Y
> dcf1    1/2/2003        2       1       N
> dcf1    1/2/2003        2       2       N
> dcf1    1/2/2003        2       3       Y
> ghg2    1/2/2003        3       1       N
> afd1    1/2/2003        3       2       N
> .....
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/flagging-values-without-a-loop-tp4632689.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

______________________________________________
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