I'm trying to modify the stats::kmeans
function to return the number of iterations (see here). When I copy the source to my own file, modify the function and run it, I get an error about object C_kmns
missing when trying to execute the do_one
function. This object is passed to a .Fortran
call and is not being created anywhere in the kmeans
function. Where does this object come from?
The error I'm getting is
Error in do_one(nmeth) : object 'C_kmns' not found
Here's a code snippet of the "offending" call.
do_one <- function(nmeth) {
Z <-
switch(nmeth,
{ # 1
Z <- .Fortran(C_kmns, as.double(x), as.integer(m),
as.integer(ncol(x)),
...
C_kmns is a non-exported object in the stats namespace. You can solve the issue by telling R where to find it with stats:::C_kmns. in your example:
Z <- .Fortran(stats:::C_kmns, as.double(x), as.integer(m),
as.integer(ncol(x)),
...
In general, when you get an object not found error, you can go looking for it with getAnywhere("C_kmns")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With