0

I am exploring this weather data in particular te Precip column from the data. I already removed non numeric values like True from there:

wwWeather <- read.csv('SummaryofWeather.csv', sep=',')$Precip
wwWeather <- unlist(Filter(is.numeric,wwWeather))

But i got errors when I want to count quantile from it.

q=quantile(wwWeather,0.90) 

I get error:

Error in quantile.default(wwWeather, 0.9) : factors are not allowed

I tried to use solutions from this thread but non of the solutions work...

The outcomes that can help:

> wwWeather
factor(0)
540 Levels: 0 0.254 0.508 0.762 1.016 1.27 1.524 1.778 10.16 10.414 10.668 10.922 100.33 100.584 100.838 101.092 101.346 101.6 101.854 ... T

> class(wwWeather)
[1] "factor"
Jaap
  • 81,064
  • 34
  • 182
  • 193
heisenberg7584
  • 563
  • 2
  • 10
  • 30
  • 1
    Does not `quantile(as.numeric(as.character(wwWeather)),0.90)` work? – s__ Dec 11 '19 at 12:45
  • What did you try? The solutions in the linked thread are right way to solve this problem. – Jaap Dec 11 '19 at 12:46
  • Your initial problem is in `unlist(Filter(is.numeric,wwWeather))`. Because in `wwWeather` is a factor, the `Filter`-part will return nothing. The root of your problem is highly likely in the data you are reading. Probably there is somewhere a 'non-numeric' string in the `Precip`-column, which causes `read.csv` to convert that column to a factor. You can either specify `na.strings` to tackle your problem or post-process with `as.numeric(as.character(read.csv('SummaryofWeather.csv', sep=',')$Precip))` – Jaap Dec 11 '19 at 13:12
  • @Jaap your solution to post-process sounds nice but I get an error: Warning message: NAs introduced by coercion – heisenberg7584 Dec 11 '19 at 13:16
  • @heisenberg7584 That confirms that there are non-numeric characters in de `Precip`-column. `as.numeric`coerces those to `NA`, so the warning is correct. To find out what characters causes the problem, you could read the data as with the first line of code in your question; then do `wwWeather2 <- as.numeric(as.character(wwWeather)` and then `wwWeather[is.na(wwWeather2)]` to find which characters are causing the problem. – Jaap Dec 11 '19 at 13:38
  • But shouldn't my `wwWeather <- unlist(Filter(is.numeric,wwWeather))` omit everything that is not numeric? Because that what I try to do, just keep numeric values and then not keep as factors in order to use `quantile` – heisenberg7584 Dec 12 '19 at 11:28

0 Answers0