0

I have a dataframe(mydat) that has no any missing data.

I use below commands:

min(mydat)

max(mydat)

for achieving the minimum and maximum values of my dataframe but for both the above functions, I get

NA

as a result in the console.

Now, I really confused and I don't know why I get that result. I appreciate if anybody shares his/her comment with me.

Mohammad
  • 103
  • 6
  • 1
    Try `min(mydat, na.rm=TRUE)` – jay.sf Nov 10 '19 at 13:41
  • `sapply(mydat, anyNA)` might help – moodymudskipper Nov 10 '19 at 15:53
  • Without seeing any of your data, all we can do is guess, which ultimately isn't very helpful for you or future SO users. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making a reproducible example – camille Nov 10 '19 at 16:00

1 Answers1

1

It's because you have NA in your data. If that isn't expected then you should investigate. If that is expected and if you want the min/max ignoring the NA values use the na.rm=TRUE parameter like

min(mydat, na.rm=TRUE)
Dason
  • 60,663
  • 9
  • 131
  • 148
  • Thanks@Dason. also my guess was as your answer. So, I run below code: `which(datExprRCT=="NA", arr.ind = TRUE)` but I couldnt find any missing value. could you please give me code for finding "NA" in mydat and remove it? – Mohammad Nov 10 '19 at 17:48
  • Use is.na(yourdata). If you try direct comparison against a string containing "NA" it won't get you anywhere. @Mohammad – Dason Nov 10 '19 at 19:03
  • ok@Dason. I found some missing values in "mydata". could you please tell me by which command I can find their indexes in "mydata"? because I have to replace a value instead of them. – Mohammad Nov 11 '19 at 05:22