'from' must be a finite number

hi i need help, i need to normalize some data using log, but the error "Error in seq.default(min(log(Datos$TotalWorkingYears)), max(log(Datos$TotalWorkingYears)), :
'from' must be a finite number" i don't know what to do

exp <- hist(Datos$TotalWorkingYears, prob =TRUE, main= 'Experiencia de los empleados', ylab='frecuencia', col='lightsalmon1') 
x<- seq(min(log(Datos$TotalWorkingYears)) , max(log(Datos$TotalWorkingYears)), length=50)
f<-dnorm(x, mean= mean(log(Datos$TotalWorkingYears),sd=sd(log(Datos$TotalWorkingYears)))
lines(x,f,col ='darkviolet', lwd=2)

If some of your data equals zero or is negative, log() returns NA. That may be the source of your problem.

If that's the issue, you might try:

x<- seq(min(log(Datos$TotalWorkingYears), na.rm=TRUE) , max(log(Datos$TotalWorkingYears), na.rm=TRUE), length=50)
1 Like

I filtered the data none of them are zero or negative

i just tried it, but the error still goes on :sob:

What does

min(log(Datos$TotalWorkingYears), na.rm=TRUE)

return?

the same error: "Error in seq.default(min(log(Datos$TotalWorkingYears), na.rm = TRUE), :
'from' must be a finite number"

Hmmm... Can you put the following code into it's own R chunk or run it from the console by itself? What is the output?

min(log(Datos$TotalWorkingYears), na.rm=TRUE)

(This alone shouldn't give the from error because you aren't asking to create a sequence here.)

Also, could you post the Datos$TotalWorkingYears vector (depending how long it is)?

To be clear, I suspect the problem is with the data itself, not your code, as the following seems to work fine:

x<- seq(min(log(airquality$Ozone), na.rm=TRUE) , max(log(airquality$Ozone), na.rm=TRUE), length=50)

ok, if i put the code in the chunk it doesn't throw me any error by itself,

the vector is
[1] 8 10 7 8 6 8 12 1 10 17 6 10 5 3 6 10 7 1 31 6 5 10 13 0 8 26 10 10 24 22 7 9 10 19 6 6 3 2 6 10 1 1 1 9 12 23 10 8 14 1 23 2 9 10
[55] 5 15 9 4 10 7 9 10 29 28 17 21 6 25 5 2 20 6 1 10 5 11 16 17 16 16 10 6 24 17 5 37 3 10 11 9 22 11 11 21 12 16 4 5 38 17 7 1 1 16 17 30 28 6
[109] 2 1 23 9 23 6 12 12 14 10 7 25 10 8 7 23 12 5 40 0 3 16 18 16 4 12 8 7 18 17 6 12 10 9 19 5 9 8 6 21 7 1 20 10 13 20 9 10 10 9 15 6 2 6
[163] 5 12 1 21 13 12 12 8 6 1 13 12 9 19 4 1 24 2 7 9 4 5 5 8 21 36 10 21 34 7 8 7 22 8 10 11 14 9 6 7 5 15 17 10 4 8 5 17 14 12 7 16 8 16
[217] 9 7 23 16 16 7 10 17 6 7 13 11 10 4 6 22 7 32 8 22 13 33 6 4 7 4 17 9 25 9 2 13 17 9 17 20 6 10 10 5 10 22 1 6 5 13 9 28 5 10 10 6 21 16
[271] 37 10 5 7 3 15 10 8 6 28 21 20 10 12 5 17 19 10 5 5 22 10 2 8 4 23 0 12 4 13 22 0 9 10 19 11 13 19 12 6 9 24 3 12 21 9 25 11 4 13 5 13 10 5
[325] 11 10 21 12 9 21 9 6 20 10 12 6 7 4 10 8 8 12 11 7 17 4 8 5 16 4 4 8 15 13 4 8 14 3 7 16 15 10 3 1 17 7 8 20 8 3 1 6 10 5 7 26 18 6
[379] 9 30 5 1 7 2 10 3 18 8 8 18 25 20 24 6 13 8 8 5 15 4 21 36 6 10 10 6 28 8 31 19 11 33 19 7 6 3 1 21 3 9 10 6 1 10 32 28 12 22 20 26 6 19
[433] 14 15 13 15 8 4 10 12 11 8 10 4 14 37 16 15 22 8 10 10 9 8 8 10 10 0 20 10 8 5 10 1 12 28 22 9 18 6 3 18 8 31 6 6 1 32 7 6 1 6 9 9 13 6
[487] 17 1 10 21 8 10 21 10 8 5 3 26 3 6 6 1 18 10 5 3 10 6 17 15 16 13 5 1 10 1 5 4 8 10 12 6 4 20 9 4 20 10 18 10 9 10 20 20 32 23 10 9 22 4
[541] 10 10 10 9 28 10 1 7 7 10 5 12 30 5 9 2 19 16 10 6 7 34 10 6 9 2 8 6 24 10 5 5 11 6 10 9 5 6 17 6 3 7 8 6 24 1 1 9 30 1 14 6 26 10
[595] 10 40 7 8 5 8 14 10 12 1 10 13 6 9 12 22 9 17 8 4 8 0 29 10 6 9 6 18 8 10 35 18 9 31 9 6 4 10 8 6 5 17 10 4 5 7 6 10 3 17 8 5 28 16
[649] 10 33 12 8 10 31 13 7 1 8 8 4 3 4 2 1 17 3 4 10 6 8 1 1 10 6 24 13 10 29 13 9 8 15 5 1 11 7 20 16 1 1 10 3 8 16 6 17 9 3 5 26 7 22
[703] 10 6 12 9 22 20 12 4 10 3 5 8 32 6 21 4 9 9 7 22 3 13 5 5 4 0 22 16 9 1 4 8 4 19 27 8 21 4 3 21 8 30 15 17 21 19 7 33 23 19 18 21 3 26
[757] 10 16 14 6 30 9 6 1 1 8 29 8 8 5 23 13 18 15 31 18 2 1 19 18 10 6 7 10 20 14 3 23 10 24 9 9 14 4 7 8 7 1 5 23 1 5 4 6 27 15 18 9 11 10
[811] 23 10 18 21 21 2 9 18 3 6 5 22 5 8 16 10 7 3 0 6 6 2 9 4 6 6 11 20 22 9 10 6 1 8 10 16 15 14 2 7 1 28 10 1 7 14 2 6 26 6 1 28 6 5
[865] 5 8 5 32 6 25 15 1 10 7 10 20 2 12 10 12 2 10 17 15 7 5 12 20 16 9 33 10 1 3 36 6 10 13 25 23 12 7 5 6 25 9 2 26 10 1 1 1 8 26 34 2 26 4
[919] 31 25 15 5 26 14 4 18 23 18 10 2 8 10 10 5 2 10 22 21 2 10 6 10 10 10 10 25 9 10 9 9 10 19 3 10 21 23 36 6 10 9 10 9 33 11 10 7 31 7 17 11 5 29
[973] 0 10 8 24 33 5 15 10 3 5 4 14 5 10 8 14 12 8 8 4 13 6 24 20 6 8 5 21 12 8 10 7 8 10 20 9 29 32 31 15 1 8 9 10 1 6 10 11 17 6 7 5 26 5
[1027] 7 7 7 11 13 28 11 10 24 8 7 10 15 2 16 6 7 35 20 8 6 5 15 4 12 11 1 13 29 16 5 7 16 1 4 1 16 10 6 4 8 11 8 1 5 10 4 8 14 10 26 11 24 9
[1081] 23 11 5 15 10 7 32 12 4 10 9 5 8 24 9 15 21 2 8 10 6 12 7 18 5 8 10 10 3 9 1 34 7 9 10 1 36 9 1 10 8 15 10 10 11 6 27 4 9 24 10 8 5 8
[1135] 1 27 1 4 32 6 23 6 10 10 10 7 9 10 10 7 16 6 3 0 27 11 18 15 9 10 10 10 15 8 18 14 23 7 6 5 6 10 8 9 7 7 27 19 2 11 15 30 4 13 36 14 13 19
[1189] 10 6 10 10 17 4 29 23 21 2 7 10 8 5 7 11 19 1 7 8 15 19 14 6 10 3 9 6 10 5 10 9 17 25 1 25 3 21 10 6 10 18 6 19 17 10 4 13 16 10 3 9 9 10
[1243] 21 9 10 3 6 6 6 2 10 12 6 13 8 11 9 10 1 10 12 15 6 7 34 11 5 15 27 10 6 1 5 1 13 15 5 24 15 6 19 10 14 5 9 6 7 10 15 13 11 10 7 7 11 23
[1297] 9 6 13 12 10 37 6 28 15 14 9 3 20 5 23 0 2 4 10 15 7 6 11 4 10 7 12 3 11 8 7 25 9 1 21 29 1 14 8 7 19 1 1 1 10 10 9 11 16 4 10 10 22 1
[1351] 9 24 10 5 5 12 14 18 8 9 4 8 12 10 7 1 10 6 16 6 16 6 10 20 29 8 10 28 14 1 6 5 4 5 14 9 8 6 9 10 6 20 10 7 8 10 15 9 9 10 7 35 1 21
[1405] 20 13 9 4 5 10 15 6 12 7 25 1 16 3 10 9 12 14 5 4 10 10 6 8 3 18 20 14 16 6 16 6 2 21 1 10 18 13 4 24 14 21 8 15 14 4 9 10 12 8 8 8 10 20
[1459] 4 10 5 20 21 10 5 17 9 6 17 6

i used the filter

filter(Datos, Datos$TotalWorkingYears>0) but it didn't work for the error

That helps! So there is at least one '0' datapoint and log(0) = -Inf which is causing a problem in the seq() function that isn't picked up by na.rm. How about:

TWY <- Datos$TotalWorkingYears[Datos$TotalWorkingYears>0]
min.x <- min(log(TWY))
max.x <- max(log(TWY))

x<- seq(min.x, max.x, length=50)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.