R version 2.14.1 Platform: i386-apple-darwin9.8.0/i386 (32-bit)
Objective:
Use function dens() of library lessR to plot a normal density curve and a general density curve superimposed over a histogram.
Problem:
While generating the data using e.g. rnorm() or rbinom() works well, running it on data generated by sample() returns this error:
Error in if (from == to) rep.int(from, length.out) else as.vector(c(from, :
argument is of length zero
MWE:
library(lessR)
data <- data.frame(col=sample(20))
y <- data$col
dens(y)
Question:
What causes the problem and what do I have to do if I want to have a data frame with a single column, let us say, which would contain twenty rows of values generated by the sample() function and use them as an input for the dens()?
Update (2012-11-17):
I have updated R to version 2.15.2 and lessR to version 2.6 (both are the latest available).
Using the data provided by @Roland, the error is now:
Error in seq.default(x.min, x.max, length = 200) :
'from' must be of length 1
I can understand why it does happen and allowing sample() to use a single value more than one leads to a correct result.
The current version of
lessRappears not to provide a functiondensanymore, instead there is a functionDensity.Would you consider updating your R version and the package? Why are you using the 32-bit version of R? On a Mac you should be able to use the 64-bit version.
I had a look at function
densfromlessR_2.1.1. I could not reproduce your error (because you did not useset.seedto make your code reproducible). Instead I gotError in seq(min.x, max.x, length = 200) : Object 'min.x' not foundwithy <- c(3, 4, 8, 1, 6, 14, 20, 5, 13, 17, 19, 10, 2, 12, 7, 9, 18, 11, 15, 16).Here is an excerpt from the function code:
Note that the code does not define
min.xandmax.x, ifabs(min.dev.x) == abs(max.dev.x), which is a bug. Of course that is easily fixed by changing the second if condition toif (abs(max.dev.x) >= abs(min.dev.x)) {.There might be other bugs, but it’s not worth fixing a function from an archived version of a utility package. Of course, I get a similar error with the new
Densityfunction and indeed it contains the same bug.