I am internalizing myself in this language and in this case I need to know in this case the hottest day of the month of June in the database airquality
.
My code is like this but the result it throws is without applying the order
, so it throws me right, a single value and for the month of June, only it is not the one with the lowest temperature.
miIris= head(airquality[airquality$Month == 6 & order(airquality$Temp), ], 1)
You have a logic problem here:
The comparison
airquality$Month == 6
returns a vector of logicals,TRUE
when the month is June, but itorder(airquality$Temp)
simply returns a vector of numerics greater than 0 (the position of the row once sorted), which are "coerced" to a logical value when you use the&
, and any number greater than 0 will beTRUE
, so the latter does not matter whether it is present or not. What ultimately happens is that you are trying to apply two actions, filter and order at the same time, and they should really be independent actions, for example:You can simplify the two operations in a single line, although you should sort the
data.frame
whole thing and then filter: