Reputation: 47
I need to return the max value in a vector along with the index name. Day and stock price. Desired output: Fri 34
v.stock.prices <- c(23,27,23,21,34)
names(v.stock.prices) <- c('Mon','Tues','Wed','Thurs','Fri')
max.price <- max(v.stock.prices)
print(max.price)
I get only 34 as output, how can I also return its index?
Upvotes: 2
Views: 848
Reputation: 887851
We can also use ==
v.stock.prices[v.stock.prices == max(v.stock.prices)]
Upvotes: 0