0

Code and Image

I am working on a problem which requires I create an ECDF from data. All was working well, and then it seems that all of a sudden my ECDF function started returning nonsense. To prove this I wrote the following lines of code:

set.seed(19191)
x <- rnorm(50)
x; ecdf(x)
plot(ecdf(x))

when I run these lines, I get what seems to be nonsense, as shown in the image I attached. This example is from this link: https://statisticsglobe.com/empirical-cumulative-distribution-function-ecdf-r

Can anyone help me?

JSOD
  • 3
  • 1
  • 1
    Can't reproduce - works fine for me. Can you try in a fresh session (no packages loaded, and no saved environment loaded). If you still have an issue in a fresh instance, then also post your R version and platform into the question – dww Jan 29 '22 at 19:34
  • 1
    any chance you accidentally assigned something to `ecdf`, overwriting `stats::ecdf()` function? For example `ecdf<-function(x) rep(0,length(x))` overwrites the `stats::ecdf()` function, replacing it with a new function that returns a vector of zeros the same length as the input, `x`. – langtang Jan 29 '22 at 19:40

2 Answers2

0

When I ran the same code in R it worked, so I realized it was an issue with RStudio. After updating RStudio, everything worked perfectly.

JSOD
  • 3
  • 1
0

I encountered this problem too and in my case, the problem solved by cleaning the R work place by rm(list = ls()).

M Shafaei N
  • 409
  • 3
  • 6