Question :
I’m working with a data.frame of weather data and want to know if the data is within the reading limits of the equipment. For this, the tolerance limits adopted for temperature (% with%,% with% and% with%) are -40 ° C to +60 ° C. In a new column the grades are assigned: temp_med
when the data is within that limit, temp_max
for when it is out and temp_min
when the line has no data.
Used script:
lim_temp<- (-40)<= dados_horas$temp_med & dados_horas$temp_med <= 60
dados_horas$nota1_temp_med [lim_temp] <- 5L
dados_horas$nota1_temp_med [!lim_temp] <- 6L
dados_horas$nota1_temp_med <- 7L
obs: 1
– Name of my database; 3
– column I want to work with; 7
– new column with notes.
But it’s popping up with the following error:
Warning messages:
1: In Ops.factor (data_time $ temp_med, (-40)):
‘<‘ not meaningful for factors
2: In Ops.factor (data_time $ temp_med, 60):
‘
Answer :
As pointed out in the comments by @RuiBarradas, the error message is reporting that this operation is not significant for factors.
In the r , factors are categorical variables. And there is in fact no reason to believe that there could be comparisons of the greater or lesser type between variables such as “Man” / “Woman” or “Asia” / “America” / “Africa”.
This problem occurred because numeric data was read as factor . To solve it, simply transform the data to numeric.
In the solution proposed by @RuiBarradas in the comments,
dados_horas$temp_med <- as.numeric(as.character(dados_horas$temp_med))
It is worth remembering that to transform data from factor to numeric it is necessary, before transforming it into text.