I know max(diamonds$price) is the way to find the price of the most expensive one. I do not know how to find its weight
CodePudding user response:
diamonds$weight[diamonds$price == max(diamonds$price)]
Meaning, extract vector weight
from data.frame diamonds
, filtering at the rows where price
is equal to the max price
.
CodePudding user response:
> df <- data.frame(price = c(1, 2, 3),
weight = c(10, 5, 2))
> df
price weight
1 1 10
2 2 5
3 3 2
> df[which.max(df$price), ]$weight
[1] 2