So I'm working on a class dealing with RStudio, and I'm clueless when it comes to this. We've had approximately 3 hours of online class based on RStudio. We did transformations to create new variables (roa, current ratio etc) and now we try to calculate mean using mean(dataframe$variable, na.rm = TRUE) and we continuously get either NaN or INF. Any suggestions?
Asked
Active
Viewed 540 times
0
-
8Hi. You have to provide your code and/or sample data. It is hard to find your mistake without seeing what you did. – Bloxx Feb 02 '22 at 23:45
-
4It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. There doesn't seem to be a problem with your code so there is likely a problem with your data and that's the part we can't see at the moment. – MrFlick Feb 02 '22 at 23:46
-
3You'll get `NaN` if the column contains all NA values, and `Inf` if the column contains any Inf values. So you need to check the data and see why that is. – neilfws Feb 02 '22 at 23:55
-
Please provide enough code so others can better understand or reproduce the problem. – Community Feb 11 '22 at 13:01
1 Answers
2
Nan = Not a Number
Inf = Infinite
As you are not showing code, it's hard for me to infer how you are getting this values. Here are 2 simple math examples to obtain both of them. One is the division by 0 and the other is 0/0:
> 10/0
[1] Inf
> 0/0
[1] NaN
>
And here you have 2 examples applied to vectors which can represent your [row,column] values for 1 column:
> mean(c(NA,NA,NA,NA),na.rm = TRUE)
[1] NaN
> mean(c(1,2,3,NA,Inf),na.rm = TRUE)
[1] Inf

AugtPelle
- 549
- 1
- 10