Error: In Ops.factor

Asked

Viewed 384 times

5

I’m working with a weather data.frame and I want to know if the data is within the reading limits of the equipment. For this purpose the tolerance limits adopted for temperature (temp_med, temp_max and temp_min) are -40° C a + 60 ° C. In a new column notes are assigned: 1 when the data are within that limit, 3 for when you’re away and 7 when the line has no data.

Script used:

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: dados_horas - Name of my database; temp_med - column I want to work; nota1_temp_med - new column with the notes.

But is appearing the following error:

Warning messages: 1: In Ops.factor(dates_hours$temp_med, (-40)) : huh<' not Meaningful for factors 2: In Ops.factor(time_hours$temp_med, 60) : pra<=' not Meaningful for factors

What must I do to correct this mistake?

Part of the database:

dia data    hora    temp_med    temp_max    temp_min
1   01/01/2012  12:00:20 AM 20.345  20.517  20.145
1   01/01/2012  1:00:07 AM  20.242  20.523  20.021
1   01/01/2012  2:00:08 AM  19.916  20.071  19.462
1   01/01/2012  3:00:08 AM  19.332  19.452  19.26
1   01/01/2012  4:00:08 AM  19.1    19.449  18.528
1   01/01/2012  5:00:08 AM  18.434  18.526  18.398
1   01/01/2012  6:00:08 AM  18.411  18.443  18.379
1   01/01/2012  7:00:08 AM  18.663  19.087  18.396
1   01/01/2012  8:00:07 AM  19.576  20.089  19.097
1   01/01/2012  9:00:07 AM  20.613  21.393  20.06
1   01/01/2012  10:00:07 AM 22.22   23.83   21.4
1   01/01/2012  11:00:07 AM 23.412  23.875  22.842
1   01/01/2012  12:00:08 PM 23.87   24.774  23.222
1   01/01/2012  1:00:08 PM  22.195  24.474  20.645
1   01/01/2012  2:00:08 PM  23.03   23.579  22.674
1   01/01/2012  3:00:08 PM  24.016  24.845  22.82
1   01/01/2012  4:00:08 PM  24.095  25.074  23.343
1   01/01/2012  5:00:08 PM  23.831  25.064  23.193
1   01/01/2012  6:00:08 PM  22.71   23.203  21.944
1   01/01/2012  7:00:07 PM  22.036  22.629  21.277
1   01/01/2012  8:00:07 PM  20.959  21.32   20.503
1   01/01/2012  9:00:07 PM  20.208  20.659  19.583
1   01/01/2012  10:00:07 PM 19.743  20.029  19.381
1   01/01/2012  11:00:07 PM 19.98   20.224  19.709
2   02/01/2012  12:00:20 AM 20.032  20.149  19.872
  • 1

    That mistake means that temp_med is being read as factor Do dados_horas$temp_med <- as.numeric(as.character(dados_horas$temp_med)).

1 answer

1

As pointed out in comments by @Ruibarradas, the error message is stating that this operation is not significant for factors.

In the , factors are categorical variables. And indeed there is no reason to believe that there can be comparisons of the major or minor type between variables such as "Man"/"Woman" or "Asia"/"America"/"Africa".

This problem occurred because numerical data were read as factor. To solve it, just turn the data to numerical.

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 factor data to numerical it is necessary, before transforming it into text.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.