Hi. Yes it is possible.
Here is one approach:
DF <- read.table(textConnection("
Unit DayHour Price Flag
afd11/2/20031 1 N
afd11/2/20031 2 N
afd11/2/20031 3 N
afd11/2/20031 4 Y
dcf11/2/2003
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
O
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
afd11/2/20031 1 N
afd11/2/20031 2
3 matches
Mail list logo